diff --git a/src/components/services/widgets/service/transmission.jsx b/src/components/services/widgets/service/transmission.jsx index 22d75288c..f8f1f25d4 100644 --- a/src/components/services/widgets/service/transmission.jsx +++ b/src/components/services/widgets/service/transmission.jsx @@ -28,16 +28,17 @@ export default function Transmission({ service }) { ); } - const torrents = torrentData.arguments.torrents; + const { torrents } = torrentData.arguments; let rateDl = 0; let rateUl = 0; let completed = 0; - for (let torrent of torrents) { + for (let i = 0; i < torrents.length; i += 1) { + const torrent = torrents[i]; rateDl += torrent.rateDownload; rateUl += torrent.rateUpload; if (torrent.percentDone === 1) { - completed++; + completed += 1; } } diff --git a/src/utils/proxies/transmission.js b/src/utils/proxies/transmission.js index 250b235c2..cd909a68b 100644 --- a/src/utils/proxies/transmission.js +++ b/src/utils/proxies/transmission.js @@ -1,6 +1,5 @@ import { httpProxy } from "utils/http"; import { formatApiCall } from "utils/api-helpers"; - import getServiceWidget from "utils/service-helpers"; export default async function transmissionProxyHandler(req, res) { @@ -20,6 +19,7 @@ export default async function transmissionProxyHandler(req, res) { const csrfHeaderName = "x-transmission-session-id"; const method = "POST"; + const auth = `${widget.username}:${widget.password}`; const body = JSON.stringify({ method: "torrent-get", arguments: { @@ -27,27 +27,27 @@ export default async function transmissionProxyHandler(req, res) { } }); - const reqHeaders = { + const headers = { "content-type": "application/json", }; let [status, contentType, data, responseHeaders] = await httpProxy(url, { - method: method, - auth: `${widget.username}:${widget.password}`, - body: body, - headers: reqHeaders, + method, + auth, + body, + headers, }); if (status === 409) { // Transmission is rejecting the request, but returning a CSRF token - reqHeaders[csrfHeaderName] = responseHeaders[csrfHeaderName]; + headers[csrfHeaderName] = responseHeaders[csrfHeaderName]; // retry the request, now with the CSRF token - [status, contentType, data] = await httpProxy(url, { - method: method, - auth: `${widget.username}:${widget.password}`, - body: body, - headers: reqHeaders, + [status, contentType, data, responseHeaders] = await httpProxy(url, { + method, + auth, + body, + headers, }); }