Implemented login, autologin; Fixed search and user favorites
This commit is contained in:
parent
dfd66e5164
commit
d672b9bc55
@ -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})
|
||||
|
@ -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)
|
||||
|
@ -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 }
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
})
|
||||
|
2
webui
2
webui
@ -1 +1 @@
|
||||
Subproject commit 39a178cfc7d67387c63323038a8533d6d84b0cc1
|
||||
Subproject commit 6baf7d989bafdf1100422d03308ddedf49af1c2c
|
Loading…
Reference in New Issue
Block a user