UNPKG

bandcamp-fetch

Version:
61 lines 3.25 kB
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 _LimiterArticleAPI_limiter; import BaseAPIWithImageSupport from '../common/BaseAPIWithImageSupport.js'; import { URLS } from '../utils/Constants.js'; import { normalizeUrl } from '../utils/Parse.js'; import ArticleCategoryParser from './ArticleCategoryParser.js'; import ArticleListParser from './ArticleListParser.js'; import ArticleParser from './ArticleParser.js'; export default class ArticleAPI extends BaseAPIWithImageSupport { async getCategories() { const html = await this.fetch(URLS.DAILY); return ArticleCategoryParser.parseCategories(html); } async getArticle(params) { const imageConstants = await this.imageAPI.getConstants(); const opts = { imageBaseUrl: imageConstants.baseUrl, albumImageFormat: await this.imageAPI.getFormat(params.albumImageFormat, 9), artistImageFormat: await this.imageAPI.getFormat(params.artistImageFormat, 21), includeRawData: !!params.includeRawData }; const html = await this.fetch(params.articleUrl); return ArticleParser.parseArticle(html, opts); } async list(params) { let url = params?.categoryUrl ? params.categoryUrl : normalizeUrl('latest', URLS.DAILY); if (params?.page) { url += `?page=${params.page}`; } const opts = { imageFormat: await this.imageAPI.getFormat(params?.imageFormat) }; const html = await this.fetch(url); return ArticleListParser.parseList(html, opts); } } export class LimiterArticleAPI extends ArticleAPI { constructor(params) { super(params); _LimiterArticleAPI_limiter.set(this, void 0); __classPrivateFieldSet(this, _LimiterArticleAPI_limiter, params.limiter, "f"); } async getCategories() { return __classPrivateFieldGet(this, _LimiterArticleAPI_limiter, "f").schedule(() => super.getCategories()); } async getArticle(params) { return __classPrivateFieldGet(this, _LimiterArticleAPI_limiter, "f").schedule(() => super.getArticle(params)); } } _LimiterArticleAPI_limiter = new WeakMap(); //# sourceMappingURL=ArticleAPI.js.map