Skip to content

Commit

Permalink
-ImportFullPrivacy: fixed import would crash if more than 10 entries …
Browse files Browse the repository at this point in the history
…in a row were not songs
  • Loading branch information
Yooooomi committed Jun 23, 2023
1 parent e1d24a1 commit 6bd049b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions server/src/tools/importers/full_privacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export class FullPrivacyImporter
static idFromSpotifyURI = (uri: string) => uri.split(':')[2];

search = async (spotifyIds: string[]) => {
if (spotifyIds.length === 0) {
return [];
}
const res = await retryPromise(
() => this.spotifyApi.getTracksFromIds(spotifyIds),
10,
Expand Down
5 changes: 3 additions & 2 deletions server/src/tools/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,20 @@ export const retryPromise = async <T>(
max: number,
time: number,
): Promise<T> => {
let lastError: Error | undefined;
for (let i = 0; i < max; i += 1) {
try {
// eslint-disable-next-line no-await-in-loop
const res = await fn();
return res;
} catch (e) {
lastError = e;
logger.error(`Retrying crashed promise, ${i + 1}/${max}`, e);
// eslint-disable-next-line no-await-in-loop
await wait(time * 1000);
}
}
// Cannot happen
return null as any;
throw lastError;
};

export const minOfArray = <T>(array: T[], fn: (item: T) => number) => {
Expand Down

0 comments on commit 6bd049b

Please sign in to comment.