Fixed alreadyInQueue not working properly

This commit is contained in:
RemixDev 2021-05-29 20:37:12 +02:00
parent b0419964f4
commit 40302ff756
6 changed files with 16 additions and 15 deletions

View File

@ -21,7 +21,7 @@
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",
"debug": "2.6.9", "debug": "2.6.9",
"deemix": "^0.1.0", "deemix": "^0.1.1",
"deezer-js": "^0.0.10", "deezer-js": "^0.0.10",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"express": "4.17.1", "express": "4.17.1",

5
server/dist/main.js vendored
View File

@ -81,12 +81,12 @@ function addToQueue(dz, url, bitrate) {
if (url.length > 1) { if (url.length > 1) {
exports.listener.send("finishGeneratingItems", { uuid: requestUUID, total: downloadObjs.length }); exports.listener.send("finishGeneratingItems", { uuid: requestUUID, total: downloadObjs.length });
} }
const isSingleObject = downloadObjs.length == 1;
const slimmedObjects = []; const slimmedObjects = [];
downloadObjs.forEach((downloadObj) => { downloadObjs.forEach((downloadObj, pos) => {
// Check if element is already in queue // Check if element is already in queue
if (Object.keys(exports.queue).includes(downloadObj.uuid)) { if (Object.keys(exports.queue).includes(downloadObj.uuid)) {
exports.listener.send('alreadyInQueue', downloadObj.getEssentialDict()); exports.listener.send('alreadyInQueue', downloadObj.getEssentialDict());
delete downloadObjs[pos];
return; return;
} }
// Save queue status when adding something to the queue // Save queue status when adding something to the queue
@ -101,6 +101,7 @@ function addToQueue(dz, url, bitrate) {
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject)); fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject));
slimmedObjects.push(downloadObj.getSlimmedDict()); slimmedObjects.push(downloadObj.getSlimmedDict());
}); });
const isSingleObject = downloadObjs.length == 1;
if (isSingleObject) if (isSingleObject)
exports.listener.send('addedToQueue', downloadObjs[0].getSlimmedDict()); exports.listener.send('addedToQueue', downloadObjs[0].getSlimmedDict());
else else

View File

@ -15,7 +15,7 @@
"dependencies": { "dependencies": {
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",
"debug": "2.6.9", "debug": "2.6.9",
"deemix": "^0.1.0", "deemix": "^0.1.1",
"deezer-js": "^0.0.10", "deezer-js": "^0.0.10",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"express": "4.17.1", "express": "4.17.1",

View File

@ -76,17 +76,16 @@ export async function addToQueue(dz: any, url: string[], bitrate: number) {
listener.send("finishGeneratingItems", {uuid: requestUUID, total: downloadObjs.length}) listener.send("finishGeneratingItems", {uuid: requestUUID, total: downloadObjs.length})
} }
const isSingleObject = downloadObjs.length == 1
const slimmedObjects: any[] = [] const slimmedObjects: any[] = []
downloadObjs.forEach((downloadObj: any) => { downloadObjs.forEach((downloadObj: any, pos: number) => {
// Check if element is already in queue // Check if element is already in queue
if (Object.keys(queue).includes(downloadObj.uuid)){ if (Object.keys(queue).includes(downloadObj.uuid)){
listener.send('alreadyInQueue', downloadObj.getEssentialDict()) listener.send('alreadyInQueue', downloadObj.getEssentialDict())
delete downloadObjs[pos]
return return
} }
// Save queue status when adding something to the queue // Save queue status when adding something to the queue
if (!fs.existsSync(configFolder + 'queue')) fs.mkdirSync(configFolder + 'queue') if (!fs.existsSync(configFolder + 'queue')) fs.mkdirSync(configFolder + 'queue')
@ -101,6 +100,7 @@ export async function addToQueue(dz: any, url: string[], bitrate: number) {
slimmedObjects.push(downloadObj.getSlimmedDict()) slimmedObjects.push(downloadObj.getSlimmedDict())
}) })
const isSingleObject = downloadObjs.length == 1
if (isSingleObject) listener.send('addedToQueue', downloadObjs[0].getSlimmedDict()) if (isSingleObject) listener.send('addedToQueue', downloadObjs[0].getSlimmedDict())
else listener.send('addedToQueue', slimmedObjects) else listener.send('addedToQueue', slimmedObjects)

View File

@ -1883,10 +1883,10 @@ decompress-response@^6.0.0:
dependencies: dependencies:
mimic-response "^3.1.0" mimic-response "^3.1.0"
deemix@^0.1.0: deemix@^0.1.1:
version "0.1.0" version "0.1.1"
resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.1.0.tgz#c66424e55a7a903639dc396ecfc636c55fc6a614" resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.1.1.tgz#14f7a580cc5a96a2adb9e896b380dba6c4215130"
integrity sha512-z9UC3ShZvTNTj1BmcJTVNxRRdjmZgMzYmrdhT0934dVRefuArcJQRLOcudu8jnYHjTJw2ONnWEIrRGM+3/C/9A== integrity sha512-vgs3qpCFo3fYh/Vvxi/c0DJ+fJsj6S2LNOUJD7mC40JrEMJW0kLnDuTLr8KLrBakY57rx6eiUUyWIa26p0d1+Q==
dependencies: dependencies:
async "^3.2.0" async "^3.2.0"
browser-id3-writer "^4.4.0" browser-id3-writer "^4.4.0"

View File

@ -813,10 +813,10 @@ decompress-response@^6.0.0:
dependencies: dependencies:
mimic-response "^3.1.0" mimic-response "^3.1.0"
deemix@^0.1.0: deemix@^0.1.1:
version "0.1.0" version "0.1.1"
resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.1.0.tgz#c66424e55a7a903639dc396ecfc636c55fc6a614" resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.1.1.tgz#14f7a580cc5a96a2adb9e896b380dba6c4215130"
integrity sha512-z9UC3ShZvTNTj1BmcJTVNxRRdjmZgMzYmrdhT0934dVRefuArcJQRLOcudu8jnYHjTJw2ONnWEIrRGM+3/C/9A== integrity sha512-vgs3qpCFo3fYh/Vvxi/c0DJ+fJsj6S2LNOUJD7mC40JrEMJW0kLnDuTLr8KLrBakY57rx6eiUUyWIa26p0d1+Q==
dependencies: dependencies:
async "^3.2.0" async "^3.2.0"
browser-id3-writer "^4.4.0" browser-id3-writer "^4.4.0"