UNPKG

bandcamp-fetch

Version:
70 lines 3.77 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _LimiterShowAPI_limiter; Object.defineProperty(exports, "__esModule", { value: true }); exports.LimiterShowAPI = void 0; const BaseAPIWithImageSupport_js_1 = __importDefault(require("../common/BaseAPIWithImageSupport.js")); const Constants_js_1 = require("../utils/Constants.js"); const Fetcher_js_1 = require("../utils/Fetcher.js"); const ShowListParser_js_1 = __importDefault(require("./ShowListParser.js")); const ShowParser_js_1 = __importDefault(require("./ShowParser.js")); class ShowAPI extends BaseAPIWithImageSupport_js_1.default { async getShow(params) { const showId = new URL(params.showUrl).searchParams.get('show'); if (!showId) { throw Error('showUrl missing "show" param'); } const imageConstants = await this.imageAPI.getConstants(); const opts = { showUrl: params.showUrl, imageBaseUrl: imageConstants.baseUrl, albumImageFormat: await this.imageAPI.getFormat(params.albumImageFormat, 9), artistImageFormat: await this.imageAPI.getFormat(params.artistImageFormat, 21), showImageFormat: await this.imageAPI.getFormat(params.showImageFormat, 25) }; const [html, json] = await Promise.all([ this.fetch(params.showUrl), this.fetch(Constants_js_1.URLS.SHOW, true, Fetcher_js_1.FetchMethod.POST, { id: showId }) ]); return ShowParser_js_1.default.parseShow(html, json, opts); } async list(params) { const imageConstants = await this.imageAPI.getConstants(); const opts = { imageBaseUrl: imageConstants.baseUrl, imageFormat: await this.imageAPI.getFormat(params?.imageFormat, 25) }; const json = await this.fetch(Constants_js_1.URLS.SHOWS, true); return ShowListParser_js_1.default.parseList(json, opts); } } exports.default = ShowAPI; class LimiterShowAPI extends ShowAPI { constructor(params) { super(params); _LimiterShowAPI_limiter.set(this, void 0); __classPrivateFieldSet(this, _LimiterShowAPI_limiter, params.limiter, "f"); } async getShow(params) { return __classPrivateFieldGet(this, _LimiterShowAPI_limiter, "f").schedule(() => super.getShow(params)); } async list(params) { return __classPrivateFieldGet(this, _LimiterShowAPI_limiter, "f").schedule(() => super.list(params)); } } exports.LimiterShowAPI = LimiterShowAPI; _LimiterShowAPI_limiter = new WeakMap(); //# sourceMappingURL=ShowAPI.js.map