Skip to content

Commit

Permalink
Merge pull request #33 from ckcr4lyf/patch/fix-http-login
Browse files Browse the repository at this point in the history
Patch/fix http login
  • Loading branch information
ckcr4lyf authored May 26, 2023
2 parents 9ec6faf + 73c8665 commit 1d6c722
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 30 deletions.
4 changes: 2 additions & 2 deletions __tests__/qbittorrent/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
Expand Down
5 changes: 0 additions & 5 deletions bin/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
10 changes: 6 additions & 4 deletions build/src/qbittorrent/api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/src/qbittorrent/auth.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 50 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions src/qbittorrent/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ enum ApiEndpoints {
}

export const login = (qbittorrentSettings: QBITTORRENT_SETTINGS): Promise<AxiosResponse> => {
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',
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/qbittorrent/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}

Expand Down

0 comments on commit 1d6c722

Please sign in to comment.