From b9720ef781b1886cf736672c2eb8966def5d8a7d Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 21 May 2021 12:34:05 +0200 Subject: [PATCH] Added support for ; separated urls --- server/package.json | 2 ++ server/src/main.ts | 32 ++++++++++++++++++------ server/src/routes/api/post/addToQueue.ts | 2 +- server/yarn.lock | 15 +++++++---- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/server/package.json b/server/package.json index 061f510..a0e4e09 100644 --- a/server/package.json +++ b/server/package.json @@ -22,6 +22,7 @@ "express-session": "^1.17.1", "morgan": "1.10.0", "ramda": "0.27.1", + "uuid": "8.3.2", "ws": "7.4.5" }, "devDependencies": { @@ -35,6 +36,7 @@ "@types/node": "14.14.37", "@types/ramda": "0.27.40", "@types/supertest": "2.0.11", + "@types/uuid": "8.3.0", "@types/ws": "7.4.1", "@typescript-eslint/eslint-plugin": "4.21.0", "@typescript-eslint/parser": "4.21.0", diff --git a/server/src/main.ts b/server/src/main.ts index 866df02..485b46b 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -1,5 +1,6 @@ import fs from 'fs' import { sep } from 'path' +import { v4 as uuidv4 } from 'uuid' // @ts-expect-error import deemix from 'deemix' import WebSocket from 'ws' @@ -38,16 +39,33 @@ export let currentJob: any = null restoreQueueFromDisk() -export async function addToQueue(dz: any, url: string, bitrate: number) { +export async function addToQueue(dz: any, url: string[], bitrate: number) { if (!dz.logged_in) throw new NotLoggedIn() - console.log(`Adding ${url} to queue`) - let downloadObjs = await deemix.generateDownloadObject(dz, url, bitrate, deemixPlugins, listener) - console.log({ downloadObjs }) - const isSingleObject = !Array.isArray(downloadObjs) - console.log(downloadObjs) - if (isSingleObject) downloadObjs = [downloadObjs] + let downloadObjs: any[] = [] + let link: string = "" + const requestUUID = uuidv4() + if (url.length > 1){ + listener.send("startGeneratingItems", {uuid: requestUUID, total: url.length}) + } + + for (let i = 0; i < url.length; i++){ + link = url[i] + console.log(`Adding ${link} to queue`) + let downloadObj = await deemix.generateDownloadObject(dz, link, bitrate, deemixPlugins, listener) + if (Array.isArray(downloadObj)){ + downloadObjs.concat(downloadObj) + } else { + downloadObjs.push(downloadObj) + } + } + + if (url.length > 1){ + listener.send("finishGeneratingItems", {uuid: requestUUID, total: downloadObjs.length}) + } + + const isSingleObject = downloadObjs.length == 1 const slimmedObjects: any[] = [] downloadObjs.forEach((downloadObj: any) => { diff --git a/server/src/routes/api/post/addToQueue.ts b/server/src/routes/api/post/addToQueue.ts index 5c49743..f7c271b 100644 --- a/server/src/routes/api/post/addToQueue.ts +++ b/server/src/routes/api/post/addToQueue.ts @@ -9,7 +9,7 @@ const handler: ApiHandler['handler'] = async (req, res) => { if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() const dz = sessionDZ[req.session.id] - const url = req.query.url + const url = req.query.url.split(';') let bitrate = req.query.bitrate if (bitrate === 'null') bitrate = settings.maxBitrate let obj: any diff --git a/server/yarn.lock b/server/yarn.lock index 2e0cef1..b34c298 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -837,6 +837,11 @@ dependencies: "@types/superagent" "*" +"@types/uuid@8.3.0": + version "8.3.0" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f" + integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ== + "@types/ws@7.4.1": version "7.4.1" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.1.tgz#49eacb15a0534663d53a36fbf5b4d98f5ae9a73a" @@ -6185,16 +6190,16 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= +uuid@8.3.2, uuid@^8.3.0: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + uuid@^3.3.2: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: - version "8.3.2" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"