diff --git a/__tests__/qbittorrent/auth.test.ts b/__tests__/qbittorrent/auth.test.ts index 35f2a72..5aa21d6 100644 --- a/__tests__/qbittorrent/auth.test.ts +++ b/__tests__/qbittorrent/auth.test.ts @@ -12,9 +12,9 @@ test('loginV2', async t => { password: 'adminadmin' } - const scope = nock(fakeSettings.url).get('/api/v2/auth/login').query({ + const scope = nock(fakeSettings.url).post('/api/v2/auth/login', { username: 'admin', - password: 'adminadmin', + password: 'adminadmin' }).reply(200, {}, { 'set-cookie': 'SID=1234' }); diff --git a/bin/index.mjs b/bin/index.mjs index 3bc7ecf..6bb2622 100755 --- a/bin/index.mjs +++ b/bin/index.mjs @@ -10,7 +10,6 @@ import { tagErroredTorrents } from '../build/src/racing/tag.js' import { postRaceResumeV2 } from '../build/src/racing/completed.js' import { startMetricsServer } from '../build/src/server/appFactory.js'; import { addTorrentToRace } from '../build/src/racing/add.js'; -import data from '../package.json' assert { type: 'json' }; // This should take care of having a base config makeConfigIfNotExist(); @@ -70,8 +69,4 @@ program.command('metrics').description('Start a prometheus metrics server').acti startMetricsServer(config, api); }) -program.option('-v, --version', 'Display the version').action(() => { - console.log(`\n\nqbit-race version ${data.version}\n\n`); -}) - program.parse(); diff --git a/build/src/qbittorrent/api.js b/build/src/qbittorrent/api.js index 8652d72..3056b57 100644 --- a/build/src/qbittorrent/api.js +++ b/build/src/qbittorrent/api.js @@ -126,10 +126,12 @@ var ApiEndpoints; ApiEndpoints["transferInfo"] = "/api/v2/transfer/info"; })(ApiEndpoints || (ApiEndpoints = {})); export const login = (qbittorrentSettings) => { - return axios.get(`${qbittorrentSettings.url}${ApiEndpoints.login}`, { - params: { - username: qbittorrentSettings.username, - password: qbittorrentSettings.password, + return axios.post(`${qbittorrentSettings.url}${ApiEndpoints.login}`, { + username: qbittorrentSettings.username, + password: qbittorrentSettings.password + }, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', } }); }; diff --git a/build/src/qbittorrent/auth.js b/build/src/qbittorrent/auth.js index 8fcd0a5..fb6281c 100644 --- a/build/src/qbittorrent/auth.js +++ b/build/src/qbittorrent/auth.js @@ -4,7 +4,7 @@ export const loginV2 = async (qbittorrentSettings) => { const logger = getLoggerV3(); const response = await apiLogin(qbittorrentSettings); // TODO: Differentiate between wrong credentials vs. qbit is not listening (wrong URL / port etc.) - if (Array.isArray(response.headers['set-cookie']) === false || response.headers['set-cookie'].length === 0) { + if (response.headers['set-cookie'] === undefined || Array.isArray(response.headers['set-cookie']) === false || response.headers['set-cookie'].length === 0) { throw new Error(`Failed to authenticate`); } return new QbittorrentApi(qbittorrentSettings.url, response.headers['set-cookie'][0]); diff --git a/package-lock.json b/package-lock.json index 8d301c3..24e251b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "qbit-race", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "qbit-race", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.6", "license": "ISC", "dependencies": { "@ckcr4lyf/bencode-esm": "^0.0.2", "@ckcr4lyf/logger": "^0.0.5", - "axios": "^0.21.1", + "axios": "^1.4.0", "commander": "^9.4.0", "fastify": "^3.19.0", "form-data": "^3.0.1" @@ -423,11 +423,26 @@ } }, "node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", "dependencies": { - "follow-redirects": "^1.14.0" + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" } }, "node_modules/balanced-match": { @@ -2094,6 +2109,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -3126,11 +3146,25 @@ } }, "axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", "requires": { - "follow-redirects": "^1.14.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } } }, "balanced-match": { @@ -4335,6 +4369,11 @@ "ipaddr.js": "1.9.1" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", diff --git a/package.json b/package.json index b0160c6..3b36f48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qbit-race", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.8", "description": "Qbit utilities for racing", "main": "./bin/index.js", "type": "module", @@ -19,7 +19,7 @@ "dependencies": { "@ckcr4lyf/bencode-esm": "^0.0.2", "@ckcr4lyf/logger": "^0.0.5", - "axios": "^0.21.1", + "axios": "^1.4.0", "commander": "^9.4.0", "fastify": "^3.19.0", "form-data": "^3.0.1" diff --git a/src/qbittorrent/api.ts b/src/qbittorrent/api.ts index 956752b..4a21417 100644 --- a/src/qbittorrent/api.ts +++ b/src/qbittorrent/api.ts @@ -158,10 +158,12 @@ enum ApiEndpoints { } export const login = (qbittorrentSettings: QBITTORRENT_SETTINGS): Promise => { - return axios.get(`${qbittorrentSettings.url}${ApiEndpoints.login}`, { - params: { - username: qbittorrentSettings.username, - password: qbittorrentSettings.password, + return axios.post(`${qbittorrentSettings.url}${ApiEndpoints.login}`, { + username: qbittorrentSettings.username, + password: qbittorrentSettings.password + }, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', } }); } diff --git a/src/qbittorrent/auth.ts b/src/qbittorrent/auth.ts index b0b68c1..cae3ce7 100644 --- a/src/qbittorrent/auth.ts +++ b/src/qbittorrent/auth.ts @@ -10,7 +10,7 @@ export const loginV2 = async (qbittorrentSettings: QBITTORRENT_SETTINGS): Promis const response = await apiLogin(qbittorrentSettings); // TODO: Differentiate between wrong credentials vs. qbit is not listening (wrong URL / port etc.) - if (Array.isArray(response.headers['set-cookie']) === false || response.headers['set-cookie'].length === 0) { + if (response.headers['set-cookie'] === undefined || Array.isArray(response.headers['set-cookie']) === false || response.headers['set-cookie'].length === 0) { throw new Error(`Failed to authenticate`); }