bandcamp-fetch
Version:
Scrape Bandcamp content
63 lines • 3.02 kB
JavaScript
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _LimiterAutocompleteAPI_limiter;
import { URLS } from '../utils/Constants.js';
import AutocompleteResultsParser from './AutocompleteResultsParser.js';
import BaseAPI from '../common/BaseAPI.js';
import { FetchMethod } from '../utils/Fetcher.js';
export var AutocompleteItemType;
(function (AutocompleteItemType) {
AutocompleteItemType["Tag"] = "Tag";
AutocompleteItemType["Location"] = "Location";
})(AutocompleteItemType || (AutocompleteItemType = {}));
export default class AutocompleteAPI extends BaseAPI {
getSuggestions(params) {
if (params.itemType === AutocompleteItemType.Tag) {
return this.getAutocompleteTags(params);
}
return this.getAutocompleteLocations(params);
}
/**
* @internal
*/
async getAutocompleteTags(params) {
const payload = {
prefix: params.query
};
const json = await this.fetch(URLS.AUTOCOMPLETE.TAG, true, FetchMethod.POST, payload);
return AutocompleteResultsParser.parseTags(json);
}
/**
* @internal
*/
async getAutocompleteLocations(params) {
const payload = {
q: params.query,
n: params.limit || 5,
geocoder_fallback: true
};
const json = await this.fetch(URLS.AUTOCOMPLETE.LOCATION, true, FetchMethod.POST, payload);
return AutocompleteResultsParser.parseLocations(json);
}
}
export class LimiterAutocompleteAPI extends AutocompleteAPI {
constructor(params) {
super(params);
_LimiterAutocompleteAPI_limiter.set(this, void 0);
__classPrivateFieldSet(this, _LimiterAutocompleteAPI_limiter, params.limiter, "f");
}
getSuggestions(params) {
return __classPrivateFieldGet(this, _LimiterAutocompleteAPI_limiter, "f").schedule(() => super.getSuggestions(params));
}
}
_LimiterAutocompleteAPI_limiter = new WeakMap();
//# sourceMappingURL=AutocompleteAPI.js.map