From d672b9bc553103bd6de61d9ad144f7607c853848 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 6 May 2021 11:52:19 +0200 Subject: [PATCH] Implemented login, autologin; Fixed search and user favorites --- server/src/routes/api/get/getUserFavorites.ts | 12 ++++++------ server/src/routes/api/get/mainSearch.ts | 11 ++++++----- server/src/routes/api/get/search.ts | 19 ++++++++++++------- server/src/routes/api/post/login-arl.ts | 19 +++++++++++++++++-- server/src/routes/index.ts | 5 ++++- webui | 2 +- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/server/src/routes/api/get/getUserFavorites.ts b/server/src/routes/api/get/getUserFavorites.ts index fb4ff73..97c77a9 100644 --- a/server/src/routes/api/get/getUserFavorites.ts +++ b/server/src/routes/api/get/getUserFavorites.ts @@ -18,12 +18,12 @@ const handler: ApiHandler['handler'] = async (req, res) => { let data data = await dz.api.get_user_playlists(userID, {limit: -1}) result['playlists'] = data.data - data = await dz.api.get_user_playlists(userID, {limit: -1}) - result['playlists'] = data.data - data = await dz.api.get_user_playlists(userID, {limit: -1}) - result['playlists'] = data.data - data = await dz.api.get_user_playlists(userID, {limit: -1}) - result['playlists'] = data.data + data = await dz.api.get_user_albums(userID, {limit: -1}) + result['albums'] = data.data + data = await dz.api.get_user_artists(userID, {limit: -1}) + result['artists'] = data.data + data = await dz.api.get_user_tracks(userID, {limit: -1}) + result['tracks'] = data.data } catch { result['playlists'] = await dz.gw.get_user_playlists(userID, {limit: -1}) result['albums'] = await dz.gw.get_user_albums(userID, {limit: -1}) diff --git a/server/src/routes/api/get/mainSearch.ts b/server/src/routes/api/get/mainSearch.ts index 32ba3dd..bb8283f 100644 --- a/server/src/routes/api/get/mainSearch.ts +++ b/server/src/routes/api/get/mainSearch.ts @@ -10,7 +10,7 @@ const handler: ApiHandler['handler'] = async (req, res) => { let dz = sessionDZ[req.session.id] const term = String(req.query.term) - const results = await dz.gw.search(term) + let results = await dz.gw.search(term) const order: string[] = [] results.ORDER.forEach((element: string) => { if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].includes(element)) order.push(element) @@ -23,29 +23,30 @@ const handler: ApiHandler['handler'] = async (req, res) => { switch (topResult.type) { case 'artist': topResult.id = originalTopResult.ART_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}` + topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}/156x156-000000-80-0-0.jpg` topResult.title = originalTopResult.ART_NAME topResult.nb_fan = originalTopResult.NB_FAN break case 'album': topResult.id = originalTopResult.ALB_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}` + topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}/156x156-000000-80-0-0.jpg` topResult.title = originalTopResult.ALB_TITLE topResult.artist = originalTopResult.ART_NAME topResult.nb_song = originalTopResult.NUMBER_TRACK break case 'playlist': topResult.id = originalTopResult.PLAYLIST_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}` + topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}/156x156-000000-80-0-0.jpg` topResult.title = originalTopResult.TITLE topResult.artist = originalTopResult.PARENT_USERNAME topResult.nb_song = originalTopResult.NB_SONG break default: topResult.id = '0' - topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover' + topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover/156x156-000000-80-0-0.jpg' break } + results.TOP_RESULT = [topResult] } results.ORDER = order res.send(results) diff --git a/server/src/routes/api/get/search.ts b/server/src/routes/api/get/search.ts index 3934515..5dea51d 100644 --- a/server/src/routes/api/get/search.ts +++ b/server/src/routes/api/get/search.ts @@ -14,29 +14,34 @@ const handler: ApiHandler['handler'] = async (req, res) => { const start = parseInt(String(req.query.start)) const nb = parseInt(String(req.query.nb)) + let data; + switch (type) { case 'track': - res.send( await dz.api.search_track(term, { limit: nb, index: start }) ) + data = await dz.api.search_track(term, { limit: nb, index: start }) break case 'album': - res.send( await dz.api.search_album(term, { limit: nb, index: start }) ) + data = await dz.api.search_album(term, { limit: nb, index: start }) break case 'artist': - res.send( await dz.api.search_artist(term, { limit: nb, index: start }) ) + data = await dz.api.search_artist(term, { limit: nb, index: start }) break case 'playlist': - res.send( await dz.api.search_playlist(term, { limit: nb, index: start }) ) + data = await dz.api.search_playlist(term, { limit: nb, index: start }) break case 'radio': - res.send( await dz.api.search_radio(term, { limit: nb, index: start }) ) + data = await dz.api.search_radio(term, { limit: nb, index: start }) break case 'user': - res.send( await dz.api.search_user(term, { limit: nb, index: start }) ) + data = await dz.api.search_user(term, { limit: nb, index: start }) break default: - res.send( await dz.api.search(term, { limit: nb, index: start }) ) + data = await dz.api.search(term, { limit: nb, index: start }) break } + + data.type = type + res.send(data) } const apiHandler: ApiHandler = { path, handler } diff --git a/server/src/routes/api/post/login-arl.ts b/server/src/routes/api/post/login-arl.ts index c2c5996..8525a7a 100644 --- a/server/src/routes/api/post/login-arl.ts +++ b/server/src/routes/api/post/login-arl.ts @@ -9,6 +9,14 @@ export interface RawLoginArlQuery { child?: number } +const LoginStatus = { + NOT_AVAILABLE: -1, + FAILED: 0, + SUCCESS: 1, + ALREADY_LOGGED: 2, + FORCED_SUCCESS: 3 +} + const path: ApiHandler['path'] = '/login-arl/' const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, next) => { @@ -36,13 +44,20 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, n let response if (process.env.NODE_ENV !== 'test') { - response = await dz.login_via_arl(...loginParams) + if (!dz.logged_in){ + response = await dz.login_via_arl(...loginParams) + response = response ? 1 : 0 + } else { + response = LoginStatus.ALREADY_LOGGED + } } else { const testDz = new Deezer() response = await testDz.login_via_arl(...loginParams) } + console.log(response) + let returnValue = {status: response, arl: req.query.arl, user: dz.current_user} - res.status(200).send(response) + res.status(200).send(returnValue) next() } diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index e21bfa2..b60e3e6 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -16,6 +16,8 @@ router.get('/', (_, res) => { router.get('/connect', (req, res) => { if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() + let dz = sessionDZ[req.session.id] + res.send({ update: { currentCommit: "testing", @@ -23,7 +25,8 @@ router.get('/connect', (req, res) => { updateAvailable: false, deemixVersion: "3.0_beta" }, - autologin: true, + autologin: !dz.logged_in, + currentUser: dz.current_user, deezerNotAvailable: false }) }) diff --git a/webui b/webui index 39a178c..6baf7d9 160000 --- a/webui +++ b/webui @@ -1 +1 @@ -Subproject commit 39a178cfc7d67387c63323038a8533d6d84b0cc1 +Subproject commit 6baf7d989bafdf1100422d03308ddedf49af1c2c