diff --git a/api/spotify.ts b/api/spotify.ts index d4b6a1f..9b5ebdf 100644 --- a/api/spotify.ts +++ b/api/spotify.ts @@ -168,7 +168,9 @@ const getCurrentUsersPlaylistsNextPage: ( }); }; -interface GetPlaylistDetailsFirstPageArgs extends EndpointHandlerWithResArgs { +interface GetPlaylistDetailsFirstPageArgs + extends Omit { + res?: Res; initialFields: string; playlistID: string; } @@ -181,16 +183,17 @@ const getPlaylistDetailsFirstPage: ( initialFields, playlistID, }) => { - return await singleRequest({ + let args: SingleRequestArgs = { authHeaders, - res, path: `/playlists/${playlistID}/`, config: { params: { fields: initialFields, }, }, - }); + }; + if (res) args.res = res; + return await singleRequest(args); }; interface GetPlaylistDetailsNextPageArgs extends EndpointHandlerWithResArgs { @@ -254,7 +257,9 @@ const removePlaylistItems: ( // non-endpoints, i.e. convenience wrappers // --------- -interface CheckPlaylistEditableArgs extends EndpointHandlerWithResArgs { +interface CheckPlaylistEditableArgs + extends Omit { + res?: Res; playlistID: string; userID: string; } @@ -272,12 +277,13 @@ const checkPlaylistEditable: ( userID, }) => { let checkFields = ["collaborative", "owner(id)"]; - const { resp, error, message } = await getPlaylistDetailsFirstPage({ - res, + let args: GetPlaylistDetailsFirstPageArgs = { authHeaders, initialFields: checkFields.join(), playlistID, - }); + }; + if (res) args.res = res; + const { resp, error, message } = await getPlaylistDetailsFirstPage(args); if (!resp) return { status: false, error, message }; // https://web.archive.org/web/20241226081630/https://developer.spotify.com/documentation/web-api/concepts/playlists#:~:text=A%20playlist%20can%20also%20be%20made%20collaborative diff --git a/controllers/operations.ts b/controllers/operations.ts index 5b7a30e..22e4531 100644 --- a/controllers/operations.ts +++ b/controllers/operations.ts @@ -687,6 +687,19 @@ const populateChain: RequestHandler = async (req, res) => { // (although that's a challenge of its own) const newGraph = new myGraph(playlistIDs, allLinks); const affectedPlaylists = newGraph.getAllHeads(rootPl.id); + + const editableStatuses = await Promise.all( + affectedPlaylists.map((pl) => { + return checkPlaylistEditable({ + authHeaders, + playlistID: pl, + userID: uID, + }); + }) + ); + if (editableStatuses.some((statusObj) => statusObj.status === false)) + return null; + const affectedPlaylistsTracks = await Promise.all( affectedPlaylists.map((pl) => { return _getPlaylistTracks({ res, authHeaders, playlistID: pl });