Skip to content

Commit db8215d

Browse files
authored
feat: Adds updateTorrentTrackers function and fixes issue #70 (#71)
* Fix bug caused in issue #70 * Add function to update trackers of a torrent by force re-announce * Add test for updateTorrentTrackers function
1 parent 4f47750 commit db8215d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Diff for: src/index.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515

1616
import {
1717
AddTorrentOptions,
18-
AddTorrentResponse,
1918
BooleanStatus,
2019
ConfigResponse,
2120
DefaultResponse,
@@ -237,7 +236,7 @@ export class Deluge implements TorrentClient {
237236
async addTorrent(
238237
torrent: string | Buffer,
239238
config: Partial<AddTorrentOptions> = {},
240-
): Promise<AddTorrentResponse> {
239+
): Promise<BooleanStatus> {
241240
const upload = await this.upload(torrent);
242241
if (!upload.success || !upload.files.length) {
243242
throw new Error('Failed to upload');
@@ -263,9 +262,9 @@ export class Deluge implements TorrentClient {
263262
super_seeding: false,
264263
...config,
265264
};
266-
const res = await this.request<AddTorrentResponse>('web.add_torrents', [[{ path, options }]]);
265+
const res = await this.request<BooleanStatus>('web.add_torrents', [[{ path, options }]]);
267266

268-
if (res.body.result[0][0] === false) {
267+
if (res.body.result === false) {
269268
throw new Error('Failed to add torrent');
270269
}
271270

@@ -515,6 +514,11 @@ export class Deluge implements TorrentClient {
515514
return req.body;
516515
}
517516

517+
async updateTorrentTrackers(torrentId: string): Promise<DefaultResponse> {
518+
const req = await this.request<DefaultResponse>('core.force_reannounce', [[torrentId]]);
519+
return req.body;
520+
}
521+
518522
async verifyTorrent(torrentId: string): Promise<DefaultResponse> {
519523
const req = await this.request<DefaultResponse>('core.force_recheck', [[torrentId]]);
520524
return req.body;

Diff for: src/types.ts

-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ export interface ListMethods extends DefaultResponse {
1919
result: string[];
2020
}
2121

22-
export interface AddTorrentResponse extends DefaultResponse {
23-
/**
24-
* tuple of [result, torrent_hash_id]
25-
*/
26-
result: Array<[boolean, string]>;
27-
}
28-
2922
// {"files": ["/tmp/delugeweb-5Q9ttR/tmpL7xhth.torrent"], "success": true}
3023
/**
3124
* ex -

Diff for: test/index.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ describe('Deluge', () => {
208208
const key = Object.keys(res.result.torrents)[0];
209209
await deluge.verifyTorrent(key);
210210
});
211+
it('should update torrent trackers', async () => {
212+
const deluge = new Deluge({ baseUrl });
213+
const res = await setupTorrent(deluge);
214+
const key = Object.keys(res.result.torrents)[0];
215+
await deluge.updateTorrentTrackers(key);
216+
});
211217
it('should add label', async () => {
212218
const client = new Deluge({ baseUrl });
213219
const list = await setupTorrent(client);

0 commit comments

Comments
 (0)