Enhancement: support qBittorrent v5.2.0 api changes (#6652)

This commit is contained in:
shamoon
2026-05-10 06:51:22 -07:00
committed by GitHub
parent d65e5447e4
commit 1cc4608d72
2 changed files with 21 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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" });