Fix limiter throwing private access errors
This commit is contained in:
parent
59a78fd5ed
commit
eace49cb14
|
@ -22,13 +22,16 @@ export default class AutocompleteAPI {
|
||||||
static getSuggestions(params: AutocompleteAPIGetSuggestionsParams): Promise<AutoCompleteTag[] | AutocompleteLocation[]>;
|
static getSuggestions(params: AutocompleteAPIGetSuggestionsParams): Promise<AutoCompleteTag[] | AutocompleteLocation[]>;
|
||||||
static getSuggestions(params: AutocompleteAPIGetSuggestionsParams): Promise<any> {
|
static getSuggestions(params: AutocompleteAPIGetSuggestionsParams): Promise<any> {
|
||||||
if (params.itemType === AutocompleteItemType.Tag) {
|
if (params.itemType === AutocompleteItemType.Tag) {
|
||||||
return this.#getAutocompleteTags(params);
|
return this.getAutocompleteTags(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.#getAutocompleteLocations(params);
|
return this.getAutocompleteLocations(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #getAutocompleteTags(params: AutocompleteAPIGetSuggestionsParams) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static async getAutocompleteTags(params: AutocompleteAPIGetSuggestionsParams) {
|
||||||
const payload = {
|
const payload = {
|
||||||
search_term: params.query,
|
search_term: params.query,
|
||||||
count: params.limit || 5
|
count: params.limit || 5
|
||||||
|
@ -38,7 +41,10 @@ export default class AutocompleteAPI {
|
||||||
return AutocompleteResultsParser.parseTags(json);
|
return AutocompleteResultsParser.parseTags(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #getAutocompleteLocations(params: AutocompleteAPIGetSuggestionsParams) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static async getAutocompleteLocations(params: AutocompleteAPIGetSuggestionsParams) {
|
||||||
const payload = {
|
const payload = {
|
||||||
q: params.query,
|
q: params.query,
|
||||||
n: params.limit || 5,
|
n: params.limit || 5,
|
||||||
|
|
|
@ -46,21 +46,21 @@ export default class BandAPI {
|
||||||
imageFormat: await ImageAPI.getFormat(params.imageFormat, 21)
|
imageFormat: await ImageAPI.getFormat(params.imageFormat, 21)
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = this.#getUrl(params.bandUrl);
|
const url = this.getUrl(params.bandUrl);
|
||||||
const html = await fetchPage(url);
|
const html = await fetchPage(url);
|
||||||
const result = BandInfoParser.parseInfo(html, opts);
|
const result = BandInfoParser.parseInfo(html, opts);
|
||||||
// Return if result is complete
|
// Return if result is complete
|
||||||
if (this.#isInfoComplete(result)) {
|
if (this.isInfoComplete(result)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info lacking name or label (for artist) - try getting them from music page
|
// Info lacking name or label (for artist) - try getting them from music page
|
||||||
const musicUrl = this.#getUrl(params.bandUrl, 'music');
|
const musicUrl = this.getUrl(params.bandUrl, 'music');
|
||||||
const musicHtml = await fetchPage(musicUrl);
|
const musicHtml = await fetchPage(musicUrl);
|
||||||
const info = BandInfoParser.parseInfo(musicHtml, opts);
|
const info = BandInfoParser.parseInfo(musicHtml, opts);
|
||||||
this.#fillInfo(result, info);
|
this.fillInfo(result, info);
|
||||||
// Return if result is complete
|
// Return if result is complete
|
||||||
if (this.#isInfoComplete(result)) {
|
if (this.isInfoComplete(result)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ export default class BandAPI {
|
||||||
if (url) {
|
if (url) {
|
||||||
const html = await fetchPage(url);
|
const html = await fetchPage(url);
|
||||||
const info = BandInfoParser.parseInfo(html, opts);
|
const info = BandInfoParser.parseInfo(html, opts);
|
||||||
this.#fillInfo(result, info);
|
this.fillInfo(result, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,10 @@ export default class BandAPI {
|
||||||
return LabelArtistsParser.parseLabelArtists(html, opts);
|
return LabelArtistsParser.parseLabelArtists(html, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getUrl(artistOrLabelUrl: string, path?: string, labelId?: string): string {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static getUrl(artistOrLabelUrl: string, path?: string, labelId?: string): string {
|
||||||
let url = path ? normalizeUrl(path, artistOrLabelUrl) : artistOrLabelUrl;
|
let url = path ? normalizeUrl(path, artistOrLabelUrl) : artistOrLabelUrl;
|
||||||
if (labelId) {
|
if (labelId) {
|
||||||
url += `/?label=${encodeURIComponent(labelId)}`;
|
url += `/?label=${encodeURIComponent(labelId)}`;
|
||||||
|
@ -101,12 +104,18 @@ export default class BandAPI {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #isInfoComplete(data: Artist | Label) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static isInfoComplete(data: Artist | Label) {
|
||||||
return data.name && data.url &&
|
return data.name && data.url &&
|
||||||
(data.type === 'label' || data.label);
|
(data.type === 'label' || data.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #fillInfo<T extends Artist | Label>(target: T, src: T): T {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static fillInfo<T extends Artist | Label>(target: T, src: T): T {
|
||||||
if (target.name === null) {
|
if (target.name === null) {
|
||||||
target.name = src.name;
|
target.name = src.name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,12 +92,15 @@ export default class DiscoveryAPI {
|
||||||
delete sanitizedParams.subgenre;
|
delete sanitizedParams.subgenre;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this.#getDiscoverRequestPayload(sanitizedParams);
|
const payload = this.getDiscoverRequestPayload(sanitizedParams);
|
||||||
const json = await fetchPage(URLS.DISCOVER_URL, true, FetchMethod.GET, payload);
|
const json = await fetchPage(URLS.DISCOVER_URL, true, FetchMethod.GET, payload);
|
||||||
return DiscoverResultParser.parseDiscoverResult(json, opts, resultParams);
|
return DiscoverResultParser.parseDiscoverResult(json, opts, resultParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getDiscoverRequestPayload(params: DiscoverParams): DiscoverRequestPayload {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static getDiscoverRequestPayload(params: DiscoverParams): DiscoverRequestPayload {
|
||||||
const result: DiscoverRequestPayload = {
|
const result: DiscoverRequestPayload = {
|
||||||
s: params.sortBy || 'top',
|
s: params.sortBy || 'top',
|
||||||
p: params.page || 0
|
p: params.page || 0
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default class FanAPI {
|
||||||
|
|
||||||
static async getInfo(params: FanAPIGetInfoParams): Promise<Fan> {
|
static async getInfo(params: FanAPIGetInfoParams): Promise<Fan> {
|
||||||
const imageConstants = await ImageAPI.getConstants();
|
const imageConstants = await ImageAPI.getConstants();
|
||||||
const fanPageUrl = this.#getFanPageUrl(params.username);
|
const fanPageUrl = this.getFanPageUrl(params.username);
|
||||||
const opts = {
|
const opts = {
|
||||||
imageBaseUrl: imageConstants.baseUrl,
|
imageBaseUrl: imageConstants.baseUrl,
|
||||||
imageFormat: await ImageAPI.getFormat(params.imageFormat, 20)
|
imageFormat: await ImageAPI.getFormat(params.imageFormat, 20)
|
||||||
|
@ -50,7 +50,7 @@ export default class FanAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getCollection(params: FanAPIGetItemsParams) {
|
static async getCollection(params: FanAPIGetItemsParams) {
|
||||||
return await this.#getItems({
|
return await this.getItems({
|
||||||
...params,
|
...params,
|
||||||
defaultImageFormat: 9,
|
defaultImageFormat: 9,
|
||||||
continuationUrl: URLS.FAN_CONTINUATION.COLLECTION,
|
continuationUrl: URLS.FAN_CONTINUATION.COLLECTION,
|
||||||
|
@ -60,7 +60,7 @@ export default class FanAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getWishlist(params: FanAPIGetItemsParams) {
|
static async getWishlist(params: FanAPIGetItemsParams) {
|
||||||
return await this.#getItems({
|
return await this.getItems({
|
||||||
...params,
|
...params,
|
||||||
defaultImageFormat: 9,
|
defaultImageFormat: 9,
|
||||||
continuationUrl: URLS.FAN_CONTINUATION.WISHLIST,
|
continuationUrl: URLS.FAN_CONTINUATION.WISHLIST,
|
||||||
|
@ -70,7 +70,7 @@ export default class FanAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFollowingArtistsAndLabels(params: FanAPIGetItemsParams) {
|
static async getFollowingArtistsAndLabels(params: FanAPIGetItemsParams) {
|
||||||
return await this.#getItems({
|
return await this.getItems({
|
||||||
...params,
|
...params,
|
||||||
defaultImageFormat: 21,
|
defaultImageFormat: 21,
|
||||||
continuationUrl: URLS.FAN_CONTINUATION.FOLLOWING_BANDS,
|
continuationUrl: URLS.FAN_CONTINUATION.FOLLOWING_BANDS,
|
||||||
|
@ -80,7 +80,7 @@ export default class FanAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFollowingGenres(params: FanAPIGetItemsParams) {
|
static async getFollowingGenres(params: FanAPIGetItemsParams) {
|
||||||
return await this.#getItems({
|
return await this.getItems({
|
||||||
...params,
|
...params,
|
||||||
defaultImageFormat: 3,
|
defaultImageFormat: 3,
|
||||||
continuationUrl: URLS.FAN_CONTINUATION.FOLLOWING_GENRES,
|
continuationUrl: URLS.FAN_CONTINUATION.FOLLOWING_GENRES,
|
||||||
|
@ -89,7 +89,10 @@ export default class FanAPI {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #getItems<T>(params: FanAPIGetItemsFullParams<T>): Promise<FanPageItemsResult<T> | FanContinuationItemsResult<T>> {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static async getItems<T>(params: FanAPIGetItemsFullParams<T>): Promise<FanPageItemsResult<T> | FanContinuationItemsResult<T>> {
|
||||||
const { target, imageFormat, defaultImageFormat, continuationUrl } = params;
|
const { target, imageFormat, defaultImageFormat, continuationUrl } = params;
|
||||||
const imageConstants = await ImageAPI.getConstants();
|
const imageConstants = await ImageAPI.getConstants();
|
||||||
const opts = {
|
const opts = {
|
||||||
|
@ -97,8 +100,8 @@ export default class FanAPI {
|
||||||
imageFormat: await ImageAPI.getFormat(imageFormat, defaultImageFormat)
|
imageFormat: await ImageAPI.getFormat(imageFormat, defaultImageFormat)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.#isContinuation(target)) {
|
if (!this.isContinuation(target)) {
|
||||||
const fanPageUrl = this.#getFanPageUrl(target as string);
|
const fanPageUrl = this.getFanPageUrl(target as string);
|
||||||
const html = await fetchPage(fanPageUrl);
|
const html = await fetchPage(fanPageUrl);
|
||||||
return params.parsePageFn(html, opts);
|
return params.parsePageFn(html, opts);
|
||||||
}
|
}
|
||||||
|
@ -118,11 +121,17 @@ export default class FanAPI {
|
||||||
return params.parseContinuationFn(json, continuation, opts);
|
return params.parseContinuationFn(json, continuation, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getFanPageUrl(username: string) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static getFanPageUrl(username: string) {
|
||||||
return `${URLS.SITE_URL}/${username}`;
|
return `${URLS.SITE_URL}/${username}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #isContinuation(target: any) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static isContinuation(target: any) {
|
||||||
return typeof target === 'object' && target.fanId && target.token;
|
return typeof target === 'object' && target.fanId && target.token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,41 +25,47 @@ export interface SearchAPISearchParams {
|
||||||
export default class SearchAPI {
|
export default class SearchAPI {
|
||||||
|
|
||||||
static async all(params: SearchAPISearchParams) {
|
static async all(params: SearchAPISearchParams) {
|
||||||
return this.#search({ ...params, itemType: SearchItemType.All });
|
return this.search({ ...params, itemType: SearchItemType.All });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async artistsAndLabels(params: SearchAPISearchParams) {
|
static async artistsAndLabels(params: SearchAPISearchParams) {
|
||||||
return this.#search({ ...params, itemType: SearchItemType.ArtistsAndLabels });
|
return this.search({ ...params, itemType: SearchItemType.ArtistsAndLabels });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async albums(params: SearchAPISearchParams) {
|
static async albums(params: SearchAPISearchParams) {
|
||||||
return this.#search({ ...params, itemType: SearchItemType.Albums });
|
return this.search({ ...params, itemType: SearchItemType.Albums });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async tracks(params: SearchAPISearchParams) {
|
static async tracks(params: SearchAPISearchParams) {
|
||||||
return this.#search({ ...params, itemType: SearchItemType.Tracks });
|
return this.search({ ...params, itemType: SearchItemType.Tracks });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fans(params: SearchAPISearchParams) {
|
static async fans(params: SearchAPISearchParams) {
|
||||||
return this.#search({ ...params, itemType: SearchItemType.Fans });
|
return this.search({ ...params, itemType: SearchItemType.Fans });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType.ArtistsAndLabels }): Promise<SearchResults<SearchResultArtist | SearchResultLabel>>;
|
/**
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType.Albums }): Promise<SearchResults<SearchResultAlbum>>;
|
* @internal
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType.Tracks }): Promise<SearchResults<SearchResultTrack>>;
|
*/
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType.Fans }): Promise<SearchResults<SearchResultFan>>;
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType.ArtistsAndLabels }): Promise<SearchResults<SearchResultArtist | SearchResultLabel>>;
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType.All }): Promise<SearchResults<SearchResultAny>>;
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType.Albums }): Promise<SearchResults<SearchResultAlbum>>;
|
||||||
static async #search(params: SearchAPISearchParams & { itemType: SearchItemType }): Promise<any> {
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType.Tracks }): Promise<SearchResults<SearchResultTrack>>;
|
||||||
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType.Fans }): Promise<SearchResults<SearchResultFan>>;
|
||||||
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType.All }): Promise<SearchResults<SearchResultAny>>;
|
||||||
|
protected static async search(params: SearchAPISearchParams & { itemType: SearchItemType }): Promise<any> {
|
||||||
const opts = {
|
const opts = {
|
||||||
itemType: params.itemType || SearchItemType.All,
|
itemType: params.itemType || SearchItemType.All,
|
||||||
albumImageFormat: await ImageAPI.getFormat(params.albumImageFormat, 9),
|
albumImageFormat: await ImageAPI.getFormat(params.albumImageFormat, 9),
|
||||||
artistImageFormat: await ImageAPI.getFormat(params.artistImageFormat, 21)
|
artistImageFormat: await ImageAPI.getFormat(params.artistImageFormat, 21)
|
||||||
};
|
};
|
||||||
const html = await fetchPage(this.#getSearchUrl(params));
|
const html = await fetchPage(this.getSearchUrl(params));
|
||||||
return SearchResultsParser.parseResults(html, opts);
|
return SearchResultsParser.parseResults(html, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getSearchUrl(params: SearchAPISearchParams & { itemType: SearchItemType }) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static getSearchUrl(params: SearchAPISearchParams & { itemType: SearchItemType }) {
|
||||||
const urlObj = new URL(URLS.SEARCH);
|
const urlObj = new URL(URLS.SEARCH);
|
||||||
urlObj.searchParams.set('q', params.query);
|
urlObj.searchParams.set('q', params.query);
|
||||||
urlObj.searchParams.set('page', (params.page || 1).toString());
|
urlObj.searchParams.set('page', (params.page || 1).toString());
|
||||||
|
|
|
@ -47,7 +47,7 @@ export default class TagAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getReleasesAvailableFilters(tagUrl: string): Promise<ReleasesByTag.Filter[]> {
|
static async getReleasesAvailableFilters(tagUrl: string): Promise<ReleasesByTag.Filter[]> {
|
||||||
const filterValueNames = await this.#getReleaseFilterValueNames(tagUrl);
|
const filterValueNames = await this.getReleaseFilterValueNames(tagUrl);
|
||||||
const html = await fetchPage(tagUrl);
|
const html = await fetchPage(tagUrl);
|
||||||
return ReleasesByTagParser.parseFilters(html, filterValueNames);
|
return ReleasesByTagParser.parseFilters(html, filterValueNames);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,10 @@ export default class TagAPI {
|
||||||
return ReleasesByTagParser.parseReleases(json, opts);
|
return ReleasesByTagParser.parseReleases(json, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #getReleaseFilterValueNames(tagUrl: string) {
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
protected static async getReleaseFilterValueNames(tagUrl: string) {
|
||||||
const url = `${tagUrl}?tab=all_releases`;
|
const url = `${tagUrl}?tab=all_releases`;
|
||||||
const html = await fetchPage(url);
|
const html = await fetchPage(url);
|
||||||
const path = ReleasesByTagParser.parseHubJSPath(html);
|
const path = ReleasesByTagParser.parseHubJSPath(html);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user