forgot to check editable status on the chain opn

This commit is contained in:
Kaushik Narayan R 2025-03-14 18:00:45 -07:00
parent 852c907d35
commit ef3a055c06
2 changed files with 27 additions and 8 deletions

View File

@ -168,7 +168,9 @@ const getCurrentUsersPlaylistsNextPage: (
});
};
interface GetPlaylistDetailsFirstPageArgs extends EndpointHandlerWithResArgs {
interface GetPlaylistDetailsFirstPageArgs
extends Omit<EndpointHandlerWithResArgs, "res"> {
res?: Res;
initialFields: string;
playlistID: string;
}
@ -181,16 +183,17 @@ const getPlaylistDetailsFirstPage: (
initialFields,
playlistID,
}) => {
return await singleRequest<GetPlaylistData>({
let args: SingleRequestArgs = {
authHeaders,
res,
path: `/playlists/${playlistID}/`,
config: {
params: {
fields: initialFields,
},
},
});
};
if (res) args.res = res;
return await singleRequest<GetPlaylistData>(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<EndpointHandlerWithResArgs, "res"> {
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

View File

@ -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 });