From 0256c80e7fbc060c2b3ec5a7385ebd17aaf797ae Mon Sep 17 00:00:00 2001 From: hammerturtle <107792503+hammerturtle@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:51:30 +0200 Subject: [PATCH 1/3] Update qbt.js --- src/qbt.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qbt.js b/src/qbt.js index e6cf217..2c1e3ab 100644 --- a/src/qbt.js +++ b/src/qbt.js @@ -8,7 +8,7 @@ const ENDPOINT = '/api/v2' * @param {string} username - Username used to access the WebUI * @param {string} password - Password used to access the WebUI */ -exports.connect = async (host, username, password) => { +exports.connect = async (host, username, password, headers = {}) => { const hostname = new URL(host) const options = { hostname: hostname.hostname, @@ -1291,11 +1291,14 @@ function performRequest(opt, cookie, path, parameters) { path: ENDPOINT + path, method: 'POST', headers: { - 'Referer': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), - 'Origin': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), - 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': data.length, - 'Cookie': cookie + ...headers, + ...{ + 'Referer': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), + 'Origin': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': data.length, + 'Cookie': cookie + }, } } From 64e714723a5251216d225a05c1e578854e4630bf Mon Sep 17 00:00:00 2001 From: hammerturtle <107792503+hammerturtle@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:56:27 +0200 Subject: [PATCH 2/3] Update qbt.js --- src/qbt.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qbt.js b/src/qbt.js index 2c1e3ab..3a57ed9 100644 --- a/src/qbt.js +++ b/src/qbt.js @@ -13,7 +13,8 @@ exports.connect = async (host, username, password, headers = {}) => { const options = { hostname: hostname.hostname, protocol: hostname.protocol, - port: parseInt(hostname.port) || (hostname.protocol == 'https:' ? 443 : 80) + port: parseInt(hostname.port) || (hostname.protocol == 'https:' ? 443 : 80), + headers, } try { @@ -1291,7 +1292,7 @@ function performRequest(opt, cookie, path, parameters) { path: ENDPOINT + path, method: 'POST', headers: { - ...headers, + ...opt.headers, ...{ 'Referer': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), 'Origin': opt.protocol + '//' + opt.hostname + ((opt.port != 80 || opt.port != 443) ? ':' + opt.port : ''), From f882d05db2be3559089dcdaa13cf2358ebaccebf Mon Sep 17 00:00:00 2001 From: hammerturtle <107792503+hammerturtle@users.noreply.github.com> Date: Tue, 6 Jun 2023 00:37:42 +0200 Subject: [PATCH 3/3] Update qbt.js --- src/qbt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qbt.js b/src/qbt.js index 3a57ed9..1710676 100644 --- a/src/qbt.js +++ b/src/qbt.js @@ -1312,7 +1312,7 @@ function performRequest(opt, cookie, path, parameters) { if (res.statusCode == 200) { var c = null if (res.headers['set-cookie'] != undefined) { - c = res.headers['set-cookie'][0] + c = res.headers['set-cookie'].filter(val => val.startsWith('SID='))[0] } resolve({ res: Buffer.concat(data).toString(), cookie: c }) } else {