mirror of
https://github.com/gethomepage/homepage.git
synced 2026-05-18 11:27:33 +08:00
Enhancement: support qBittorrent v5.2.0 api changes (#6652)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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" });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user