Send up to 3 playlist check requests to Spotify at a time

This commit is contained in:
2024-03-28 07:18:23 +01:00
parent 1ec73fe016
commit 7c01bab5a4
3 changed files with 303 additions and 101 deletions

View File

@@ -1,4 +1,5 @@
import { ApplicationFunction, Probot } from 'probot';
import { throttleAll } from 'promise-throttle-all';
import getMetaData from 'metadata-scraper';
import { getPlaylistIdFromUrl } from './getPlaylistIdFromUrl';
@@ -72,8 +73,9 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
if (filesToVerify.length === 0) return;
const playlistSearchResults = await Promise.all(
filesToVerify.map(async ({ filename }) => {
const playlistSearchResults = await throttleAll(
3,
filesToVerify.map(({ filename }) => async () => {
const filenameWithoutRegistryPath = removeRegistryPathFromFilename(
filename
).replace('https:/', 'https://');
@@ -85,9 +87,10 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
const spotifyResponse = await fetch(url);
const expectedStatusCodes = [200, 400, 404];
if (!expectedStatusCodes.includes(spotifyResponse.status)) {
throw new Error(`Spotify ${spotifyResponse.status}`);
}
if (!expectedStatusCodes.includes(spotifyResponse.status))
throw new Error(
`Spotify responded with a ${spotifyResponse.status} status code`
);
const found = spotifyResponse.status === 200;
let details = '';