Implemented login, autologin; Fixed search and user favorites

This commit is contained in:
RemixDev 2021-05-06 11:52:19 +02:00
parent dfd66e5164
commit d672b9bc55
6 changed files with 46 additions and 22 deletions

View File

@ -18,12 +18,12 @@ const handler: ApiHandler['handler'] = async (req, res) => {
let data let data
data = await dz.api.get_user_playlists(userID, {limit: -1}) data = await dz.api.get_user_playlists(userID, {limit: -1})
result['playlists'] = data.data result['playlists'] = data.data
data = await dz.api.get_user_playlists(userID, {limit: -1}) data = await dz.api.get_user_albums(userID, {limit: -1})
result['playlists'] = data.data result['albums'] = data.data
data = await dz.api.get_user_playlists(userID, {limit: -1}) data = await dz.api.get_user_artists(userID, {limit: -1})
result['playlists'] = data.data result['artists'] = data.data
data = await dz.api.get_user_playlists(userID, {limit: -1}) data = await dz.api.get_user_tracks(userID, {limit: -1})
result['playlists'] = data.data result['tracks'] = data.data
} catch { } catch {
result['playlists'] = await dz.gw.get_user_playlists(userID, {limit: -1}) result['playlists'] = await dz.gw.get_user_playlists(userID, {limit: -1})
result['albums'] = await dz.gw.get_user_albums(userID, {limit: -1}) result['albums'] = await dz.gw.get_user_albums(userID, {limit: -1})

View File

@ -10,7 +10,7 @@ const handler: ApiHandler['handler'] = async (req, res) => {
let dz = sessionDZ[req.session.id] let dz = sessionDZ[req.session.id]
const term = String(req.query.term) const term = String(req.query.term)
const results = await dz.gw.search(term) let results = await dz.gw.search(term)
const order: string[] = [] const order: string[] = []
results.ORDER.forEach((element: string) => { results.ORDER.forEach((element: string) => {
if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].includes(element)) order.push(element) 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) { switch (topResult.type) {
case 'artist': case 'artist':
topResult.id = originalTopResult.ART_ID 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.title = originalTopResult.ART_NAME
topResult.nb_fan = originalTopResult.NB_FAN topResult.nb_fan = originalTopResult.NB_FAN
break break
case 'album': case 'album':
topResult.id = originalTopResult.ALB_ID 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.title = originalTopResult.ALB_TITLE
topResult.artist = originalTopResult.ART_NAME topResult.artist = originalTopResult.ART_NAME
topResult.nb_song = originalTopResult.NUMBER_TRACK topResult.nb_song = originalTopResult.NUMBER_TRACK
break break
case 'playlist': case 'playlist':
topResult.id = originalTopResult.PLAYLIST_ID 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.title = originalTopResult.TITLE
topResult.artist = originalTopResult.PARENT_USERNAME topResult.artist = originalTopResult.PARENT_USERNAME
topResult.nb_song = originalTopResult.NB_SONG topResult.nb_song = originalTopResult.NB_SONG
break break
default: default:
topResult.id = '0' 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 break
} }
results.TOP_RESULT = [topResult]
} }
results.ORDER = order results.ORDER = order
res.send(results) res.send(results)

View File

@ -14,29 +14,34 @@ const handler: ApiHandler['handler'] = async (req, res) => {
const start = parseInt(String(req.query.start)) const start = parseInt(String(req.query.start))
const nb = parseInt(String(req.query.nb)) const nb = parseInt(String(req.query.nb))
let data;
switch (type) { switch (type) {
case 'track': 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 break
case 'album': 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 break
case 'artist': 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 break
case 'playlist': 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 break
case 'radio': 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 break
case 'user': 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 break
default: default:
res.send( await dz.api.search(term, { limit: nb, index: start }) ) data = await dz.api.search(term, { limit: nb, index: start })
break break
} }
data.type = type
res.send(data)
} }
const apiHandler: ApiHandler = { path, handler } const apiHandler: ApiHandler = { path, handler }

View File

@ -9,6 +9,14 @@ export interface RawLoginArlQuery {
child?: number child?: number
} }
const LoginStatus = {
NOT_AVAILABLE: -1,
FAILED: 0,
SUCCESS: 1,
ALREADY_LOGGED: 2,
FORCED_SUCCESS: 3
}
const path: ApiHandler['path'] = '/login-arl/' const path: ApiHandler['path'] = '/login-arl/'
const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, next) => { const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, next) => {
@ -36,13 +44,20 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, n
let response let response
if (process.env.NODE_ENV !== 'test') { 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 { } else {
const testDz = new Deezer() const testDz = new Deezer()
response = await testDz.login_via_arl(...loginParams) 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() next()
} }

View File

@ -16,6 +16,8 @@ router.get('/', (_, res) => {
router.get('/connect', (req, res) => { router.get('/connect', (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
res.send({ res.send({
update: { update: {
currentCommit: "testing", currentCommit: "testing",
@ -23,7 +25,8 @@ router.get('/connect', (req, res) => {
updateAvailable: false, updateAvailable: false,
deemixVersion: "3.0_beta" deemixVersion: "3.0_beta"
}, },
autologin: true, autologin: !dz.logged_in,
currentUser: dz.current_user,
deezerNotAvailable: false deezerNotAvailable: false
}) })
}) })

2
webui

@ -1 +1 @@
Subproject commit 39a178cfc7d67387c63323038a8533d6d84b0cc1 Subproject commit 6baf7d989bafdf1100422d03308ddedf49af1c2c