Implemented spotify plugin on server
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// @ts-expect-error
|
||||
import { Deezer } from 'deezer-js'
|
||||
import { ApiHandler } from '../../../types'
|
||||
import { sessionDZ } from '../../../main'
|
||||
import { sessionDZ, plugins } from '../../../main'
|
||||
|
||||
const path: ApiHandler['path'] = '/getTracklist'
|
||||
|
||||
@@ -18,6 +18,48 @@ const handler: ApiHandler['handler'] = async (req, res) => {
|
||||
res.send(artistAPI)
|
||||
break
|
||||
}
|
||||
case 'spotifyplaylist':
|
||||
case 'spotify_playlist': {
|
||||
if (!plugins.spotify.enabled){
|
||||
res.send({
|
||||
collaborative: false,
|
||||
description: "",
|
||||
external_urls: {spotify: null},
|
||||
followers: {total: 0, href: null},
|
||||
id: null,
|
||||
images: [],
|
||||
name: "Something went wrong",
|
||||
owner: {
|
||||
display_name: "Error",
|
||||
id: null
|
||||
},
|
||||
public: true,
|
||||
tracks : [],
|
||||
type: 'playlist',
|
||||
uri: null
|
||||
})
|
||||
break
|
||||
}
|
||||
let sp = plugins.spotify.sp
|
||||
let playlist = await sp.getPlaylist(list_id)
|
||||
playlist = playlist.body
|
||||
let tracklist = playlist.tracks.items
|
||||
while (playlist.tracks.next) {
|
||||
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next)
|
||||
let offset = regExec![1]
|
||||
let limit = regExec![2]
|
||||
let playlistTracks = await sp.getPlaylistTracks(list_id, { offset, limit })
|
||||
playlist.tracks = playlistTracks.body
|
||||
tracklist = tracklist.concat(playlist.tracks.items)
|
||||
}
|
||||
tracklist.forEach((item:any, i:number) => {
|
||||
tracklist[i] = item.track
|
||||
tracklist[i].selected = false
|
||||
});
|
||||
playlist.tracks = tracklist
|
||||
res.send(playlist)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
const releaseAPI = await dz.api[`get_${list_type}`](list_id)
|
||||
let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id)
|
||||
|
||||
Reference in New Issue
Block a user