From cc82ee6376a3c13a43f9f25a74cb77f8e7415e5a Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 13 May 2021 21:31:52 +0200 Subject: [PATCH] Added broadcast for alreadyInQueue and loginNeededToDownload errors --- server/src/main.ts | 2 +- server/src/routes/api/post/addToQueue.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/main.ts b/server/src/main.ts index fac5864..56ad4e2 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -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) { diff --git a/server/src/routes/api/post/addToQueue.ts b/server/src/routes/api/post/addToQueue.ts index 299acd1..5c49743 100644 --- a/server/src/routes/api/post/addToQueue.ts +++ b/server/src/routes/api/post/addToQueue.ts @@ -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