Skip to content

Commit

Permalink
Merge pull request #44 from ckcr4lyf/patch/get-post
Browse files Browse the repository at this point in the history
GET -> POST
  • Loading branch information
ckcr4lyf authored Nov 21, 2023
2 parents 1882490 + af1f547 commit 8945f44
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
26 changes: 26 additions & 0 deletions __tests__/qbittorrent/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,30 @@ test('getTorrentsWithParam', async t => {
const got = await api.getTorrents(['a', 'b']);

t.deepEqual(data, got);
})

test('resumeTorrents', async t => {
const api = new QbittorrentApi('http://qbit:8080', 'cookie');

const scope = nock('http://qbit:8080', {
reqheaders: {
'Cookie': 'cookie'
}
});

scope.post('/api/v2/torrents/resume', 'hashes=a|b').reply(200);

await api.resumeTorrents([
{
hash: 'a',
},
{
hash: 'b',
}
]);

// Make sure the scope was successfully called
t.notThrows(() => {
scope.done();
});
})
8 changes: 5 additions & 3 deletions build/src/qbittorrent/api.js

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

4 changes: 4 additions & 0 deletions build/src/racing/completed.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qbit-race",
"version": "2.0.0-alpha.12",
"version": "2.0.0-alpha.13",
"description": "Qbit utilities for racing",
"main": "./bin/index.js",
"type": "module",
Expand Down
12 changes: 7 additions & 5 deletions src/qbittorrent/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ export class QbittorrentApi {
})
}

async resumeTorrents(torrents: QbittorrentTorrent[]){
async resumeTorrents(torrents: ApiCompatibleTorrent[]){
const infohashes = torrents.map(torrent => torrent.hash);
const payload = `hashes=${infohashes.join('|')}`;

try {
await this.client.get(ApiEndpoints.resumeTorrents, {
params: {
hashes: torrents.map(torrent => torrent.hash).join('|'),
await this.client.post(ApiEndpoints.resumeTorrents, payload, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
});
} catch (e){
throw new Error(`Failed to resume torrents. Error: ${e}`);
}

}

async pauseTorrents(torrents: QbittorrentTorrent[]){
Expand Down
3 changes: 3 additions & 0 deletions src/racing/completed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const postRaceResumeV2 = async (api: QbittorrentApi, settings: Settings,
} catch (e){
logger.error(`Failed to send message to discord ${e}`);
}
} else {
logger.debug(`Discord notifications disabled.`)
}

// The earliest time, from which there may still be a torrent in the reannounce phase
Expand Down Expand Up @@ -79,6 +81,7 @@ export const postRaceResumeV2 = async (api: QbittorrentApi, settings: Settings,
// Try and resume
try {
await api.resumeTorrents(pausedTorrents);
logger.debug(`Successfully resumed torrents`);
} catch (e){
logger.error(`Failed to resume torrents! ${e}`);
process.exit(1);
Expand Down

0 comments on commit 8945f44

Please sign in to comment.