From 1cc4608d729c04b86b41da97916d8c244c836352 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 10 May 2026 06:51:22 -0700 Subject: [PATCH] Enhancement: support qBittorrent v5.2.0 api changes (#6652) --- src/widgets/qbittorrent/proxy.js | 4 ++-- src/widgets/qbittorrent/proxy.test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/widgets/qbittorrent/proxy.js b/src/widgets/qbittorrent/proxy.js index 4bb883023..9b789c885 100644 --- a/src/widgets/qbittorrent/proxy.js +++ b/src/widgets/qbittorrent/proxy.js @@ -41,12 +41,12 @@ export default async function qbittorrentProxyHandler(req, res) { if (status === 403) { [status, data] = await login(widget); - if (status !== 200) { + if (![200, 204].includes(status)) { logger.error("HTTP %d logging in to qBittorrent. Data: %s", status, data); return res.status(status).end(data); } - if (data.toString() !== "Ok.") { + if (status === 200 && data.toString() !== "Ok.") { logger.error("Error logging in to qBittorrent: Data: %s", data); return res.status(401).end(data); } diff --git a/src/widgets/qbittorrent/proxy.test.js b/src/widgets/qbittorrent/proxy.test.js index 8c0754e75..caea6e6d0 100644 --- a/src/widgets/qbittorrent/proxy.test.js +++ b/src/widgets/qbittorrent/proxy.test.js @@ -49,6 +49,25 @@ describe("widgets/qbittorrent/proxy", () => { expect(res.body).toEqual(Buffer.from("data")); }); + it("accepts qBittorrent 5.2.0 no-content login responses", async () => { + getServiceWidget.mockResolvedValue({ url: "http://qb", username: "u", password: "p" }); + + httpProxy + .mockResolvedValueOnce([403, "application/json", Buffer.from("nope")]) + .mockResolvedValueOnce([204, null, Buffer.from("")]) + .mockResolvedValueOnce([200, "application/json", Buffer.from("data")]); + + const req = { query: { group: "g", service: "svc", endpoint: "torrents/info", index: "0" } }; + const res = createMockRes(); + + await qbittorrentProxyHandler(req, res); + + expect(httpProxy).toHaveBeenCalledTimes(3); + expect(httpProxy.mock.calls[1][0]).toBe("http://qb/api/v2/auth/login"); + expect(res.statusCode).toBe(200); + expect(res.body).toEqual(Buffer.from("data")); + }); + it("returns 401 when login succeeds but response body is not Ok.", async () => { getServiceWidget.mockResolvedValue({ url: "http://qb", username: "u", password: "p" });