From db8215ddf3bd5c07bb506e9bd484c8d676986cbf Mon Sep 17 00:00:00 2001 From: Abhishek Datta Date: Sat, 22 Feb 2020 21:56:38 +0530 Subject: [PATCH] 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 --- src/index.ts | 12 ++++++++---- src/types.ts | 7 ------- test/index.spec.ts | 6 ++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 874f61f..c6c8b37 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,6 @@ import { import { AddTorrentOptions, - AddTorrentResponse, BooleanStatus, ConfigResponse, DefaultResponse, @@ -237,7 +236,7 @@ export class Deluge implements TorrentClient { async addTorrent( torrent: string | Buffer, config: Partial = {}, - ): Promise { + ): Promise { const upload = await this.upload(torrent); if (!upload.success || !upload.files.length) { throw new Error('Failed to upload'); @@ -263,9 +262,9 @@ export class Deluge implements TorrentClient { super_seeding: false, ...config, }; - const res = await this.request('web.add_torrents', [[{ path, options }]]); + const res = await this.request('web.add_torrents', [[{ path, options }]]); - if (res.body.result[0][0] === false) { + if (res.body.result === false) { throw new Error('Failed to add torrent'); } @@ -515,6 +514,11 @@ export class Deluge implements TorrentClient { return req.body; } + async updateTorrentTrackers(torrentId: string): Promise { + const req = await this.request('core.force_reannounce', [[torrentId]]); + return req.body; + } + async verifyTorrent(torrentId: string): Promise { const req = await this.request('core.force_recheck', [[torrentId]]); return req.body; diff --git a/src/types.ts b/src/types.ts index 1722954..feefb3d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 - diff --git a/test/index.spec.ts b/test/index.spec.ts index f99b5a3..cd498eb 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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);