From 8df11acbe84d7b95ab54c31fcfce5da26355d9bb Mon Sep 17 00:00:00 2001 From: Karl0ss Date: Fri, 16 Jun 2023 07:40:10 +0100 Subject: [PATCH] JDownloader Widget - Add Total Queue and Remaining In Queue (#1612) undefined --- public/locales/en/common.json | 7 ++++--- src/widgets/jdownloader/component.jsx | 6 ++++-- src/widgets/jdownloader/proxy.js | 23 ++++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 437088bd3..36b5a391d 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -655,8 +655,9 @@ "updates": "Updates" }, "jdownloader": { - "downloadCount": "Queue Count", - "downloadQueueSize": "Queue Size", - "downloadSpeed": "Download Speed" + "downloadCount": "Queue", + "downloadBytesRemaining": "Remaining", + "downloadTotalBytes": "Size", + "downloadSpeed": "Speed" } } diff --git a/src/widgets/jdownloader/component.jsx b/src/widgets/jdownloader/component.jsx index d8fea9caf..8f2719356 100644 --- a/src/widgets/jdownloader/component.jsx +++ b/src/widgets/jdownloader/component.jsx @@ -21,7 +21,8 @@ export default function Component({ service }) { return ( - + + ); @@ -30,7 +31,8 @@ export default function Component({ service }) { return ( - + + ); diff --git a/src/widgets/jdownloader/proxy.js b/src/widgets/jdownloader/proxy.js index 353192ac7..be858d518 100644 --- a/src/widgets/jdownloader/proxy.js +++ b/src/widgets/jdownloader/proxy.js @@ -28,8 +28,8 @@ async function getWidget(req) { async function login(loginSecret, deviceSecret, params) { const rid = uniqueRid(); - const path = `/my/connect?${querystring.stringify({...params, rid})}`; - + const path = `/my/connect?${querystring.stringify({ ...params, rid })}`; + const signature = crypto .createHmac('sha256', loginSecret) .update(path) @@ -64,7 +64,7 @@ async function login(loginSecret, deviceSecret, params) { async function getDevice(serverEncryptionToken, deviceName, params) { const rid = uniqueRid(); - const path = `/my/listdevices?${querystring.stringify({...params, rid})}`; + const path = `/my/listdevices?${querystring.stringify({ ...params, rid })}`; const signature = crypto .createHmac('sha256', serverEncryptionToken) .update(path) @@ -100,7 +100,7 @@ function createBody(rid, query, params) { rid, url: query }; - return params ? {...baseBody, params: [JSON.stringify(params)] } : baseBody; + return params ? { ...baseBody, params: [JSON.stringify(params)] } : baseBody; } async function queryPackages(deviceEncryptionToken, deviceId, sessionToken, params) { @@ -135,9 +135,9 @@ export default async function jdownloaderProxyHandler(req, res) { return res.status(400).json({ error: "Invalid proxy service type" }); } logger.debug("Getting data from JDRss API"); - const {username} = widget - const {password} = widget - + const { username } = widget + const { password } = widget + const appKey = "homepage" const loginSecret = sha256(`${username}${password}server`) const deviceSecret = sha256(`${username}${password}device`) @@ -171,17 +171,22 @@ export default async function jdownloaderProxyHandler(req, res) { } ) + let bytesRemaining = 0; let totalBytes = 0; let totalSpeed = 0; packageStatus.forEach(file => { totalBytes += file.bytesTotal; - if (file.speed) { - totalSpeed += file.speed; + if (file.finished !== true) { + bytesRemaining += file.bytesTotal; + if (file.speed) { + totalSpeed += file.speed; + } } }); const data = { downloadCount: packageStatus.length, + bytesRemaining, totalBytes, totalSpeed };