bugfixes, improving API request wrapper

This commit is contained in:
2025-03-12 22:30:26 -07:00
parent ca1ad74834
commit 7eec2adc7a
11 changed files with 105 additions and 64 deletions

View File

@@ -16,8 +16,14 @@ import logger from "../utils/logger.ts";
*/
const fetchUserPlaylists: RequestHandler = async (req, res) => {
try {
const { authHeaders } = req.session;
if (!authHeaders)
throw new ReferenceError("session does not have auth headers");
// get first 50
const respData = await getCurrentUsersPlaylistsFirstPage({ req, res });
const respData = await getCurrentUsersPlaylistsFirstPage({
authHeaders,
res,
});
if (!respData) return null;
let tmpData = structuredClone(respData);
@@ -32,7 +38,7 @@ const fetchUserPlaylists: RequestHandler = async (req, res) => {
// keep getting batches of 50 till exhausted
while (nextURL) {
const nextData = await getCurrentUsersPlaylistsNextPage({
req,
authHeaders,
res,
nextURL,
});
@@ -51,4 +57,5 @@ const fetchUserPlaylists: RequestHandler = async (req, res) => {
return null;
}
};
export { fetchUserPlaylists };