From 5b73745094152e443582b5509acf87cb301f33b7 Mon Sep 17 00:00:00 2001 From: deeplydrumming Date: Tue, 6 Aug 2024 08:41:42 +0100 Subject: [PATCH] multiple users separated by comma or spaces accepted in Spotify username field --- .../routes/api/get/getUserSpotifyPlaylists.ts | 37 +++++++++++-------- webui/src/components/pages/About.vue | 6 +++ webui/src/components/pages/Home.vue | 2 +- .../components/pages/InfoSpotifyFeatures.vue | 6 ++- webui/src/components/pages/Settings.vue | 17 ++++++--- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/server/src/routes/api/get/getUserSpotifyPlaylists.ts b/server/src/routes/api/get/getUserSpotifyPlaylists.ts index 04057be..6cf2168 100644 --- a/server/src/routes/api/get/getUserSpotifyPlaylists.ts +++ b/server/src/routes/api/get/getUserSpotifyPlaylists.ts @@ -8,24 +8,29 @@ const handler: ApiHandler['handler'] = async (req, res) => { if (deemix.plugins.spotify.enabled) { const sp = deemix.plugins.spotify.sp - const username = req.query.spotifyUser + const usernames = req.query.spotifyUser.split(/[\s,]+/) data = [] - let playlists - try { - playlists = await sp.getUserPlaylists(username) - } catch (e) { - res.send({ error: 'wrongSpotifyUsername', username }) - return - } - playlists = playlists.body - let playlistList = playlists.items - while (playlists.next) { - const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next) - const offset = regExec![1] - const limit = regExec![2] - const newPlaylists = await sp.getUserPlaylists(username, { offset, limit }) - playlists = newPlaylists.body + let playlistList: any + playlistList = [] + for (let username of usernames) { + username = username.trim() + let playlists + try { + playlists = await sp.getUserPlaylists(username) + } catch (e) { + res.send({ error: 'wrongSpotifyUsername', username }) + return + } + playlists = playlists.body playlistList = playlistList.concat(playlists.items) + while (playlists.next) { + const regExec = /offset=(\d+)/g.exec(playlists.next) + const offset = regExec![1] + // const limit = regExec![2] + const newPlaylists = await sp.getUserPlaylists(username, { offset }) + playlists = newPlaylists.body + playlistList = playlistList.concat(playlists.items) + } } playlistList.forEach((playlist: any) => { data.push(deemix.plugins.spotify._convertPlaylistStructure(playlist)) diff --git a/webui/src/components/pages/About.vue b/webui/src/components/pages/About.vue index 912f1a9..df95b8d 100644 --- a/webui/src/components/pages/About.vue +++ b/webui/src/components/pages/About.vue @@ -37,6 +37,12 @@

Changelog