Added broadcast for alreadyInQueue and loginNeededToDownload errors

This commit is contained in:
RemixDev 2021-05-13 21:31:52 +02:00
parent a82c4c303e
commit cc82ee6376
2 changed files with 6 additions and 3 deletions

View File

@ -17,7 +17,7 @@ export const sessionDZ: any = {}
const deemixPlugins = {}
export const listener = {
send(key: string, data: any) {
send(key: string, data?: any) {
console.log(key, data)
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {

View File

@ -1,7 +1,7 @@
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ, addToQueue, settings } from '../../../main'
import { sessionDZ, addToQueue, settings, listener } from '../../../main'
const path: ApiHandler['path'] = '/addToQueue'
@ -19,13 +19,16 @@ const handler: ApiHandler['handler'] = async (req, res) => {
} catch (e) {
switch (e.name) {
case 'AlreadyInQueue':
res.send({ result: false, errid: e.name, data: { url, bitrate, obj: e.data } })
res.send({ result: false, errid: e.name, data: { url, bitrate, obj: e.item } })
listener.send('alreadyInQueue', e.item)
break
case 'NotLoggedIn':
res.send({ result: false, errid: e.name, data: { url, bitrate } })
listener.send('loginNeededToDownload')
break
default:
console.error(e)
res.send({ result: false, errid: e.name, data: { url, bitrate } })
break
}
return