Skip to content

Commit

Permalink
feat: Adds updateTorrentTrackers function and fixes issue #70 (#71)
Browse files Browse the repository at this point in the history
* Fix bug caused in issue #70

* Add function to update trackers of a torrent by force re-announce

* Add test for updateTorrentTrackers function
  • Loading branch information
abdatta committed Feb 22, 2020
1 parent 4f47750 commit db8215d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

import {
AddTorrentOptions,
AddTorrentResponse,
BooleanStatus,
ConfigResponse,
DefaultResponse,
Expand Down Expand Up @@ -237,7 +236,7 @@ export class Deluge implements TorrentClient {
async addTorrent(
torrent: string | Buffer,
config: Partial<AddTorrentOptions> = {},
): Promise<AddTorrentResponse> {
): Promise<BooleanStatus> {
const upload = await this.upload(torrent);
if (!upload.success || !upload.files.length) {
throw new Error('Failed to upload');
Expand All @@ -263,9 +262,9 @@ export class Deluge implements TorrentClient {
super_seeding: false,
...config,
};
const res = await this.request<AddTorrentResponse>('web.add_torrents', [[{ path, options }]]);
const res = await this.request<BooleanStatus>('web.add_torrents', [[{ path, options }]]);

if (res.body.result[0][0] === false) {
if (res.body.result === false) {
throw new Error('Failed to add torrent');
}

Expand Down Expand Up @@ -515,6 +514,11 @@ export class Deluge implements TorrentClient {
return req.body;
}

async updateTorrentTrackers(torrentId: string): Promise<DefaultResponse> {
const req = await this.request<DefaultResponse>('core.force_reannounce', [[torrentId]]);
return req.body;
}

async verifyTorrent(torrentId: string): Promise<DefaultResponse> {
const req = await this.request<DefaultResponse>('core.force_recheck', [[torrentId]]);
return req.body;
Expand Down
7 changes: 0 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export interface ListMethods extends DefaultResponse {
result: string[];
}

export interface AddTorrentResponse extends DefaultResponse {
/**
* tuple of [result, torrent_hash_id]
*/
result: Array<[boolean, string]>;
}

// {"files": ["/tmp/delugeweb-5Q9ttR/tmpL7xhth.torrent"], "success": true}
/**
* ex -
Expand Down
6 changes: 6 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ describe('Deluge', () => {
const key = Object.keys(res.result.torrents)[0];
await deluge.verifyTorrent(key);
});
it('should update torrent trackers', async () => {
const deluge = new Deluge({ baseUrl });
const res = await setupTorrent(deluge);
const key = Object.keys(res.result.torrents)[0];
await deluge.updateTorrentTrackers(key);
});
it('should add label', async () => {
const client = new Deluge({ baseUrl });
const list = await setupTorrent(client);
Expand Down

0 comments on commit db8215d

Please sign in to comment.