Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds updateTorrentTrackers function and fixes issue #70 #71

Merged
merged 3 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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