@ctrl/transmission 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transmission.d.ts +17 -23
- package/dist/transmission.js +37 -19
- package/dist/types.d.ts +8 -3
- package/package.json +1 -1
package/dist/transmission.d.ts
CHANGED
@@ -1,45 +1,38 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Response } from 'got';
|
3
3
|
import { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentSettings } from '@ctrl/shared-torrent';
|
4
|
-
import { AddTorrentOptions, AddTorrentResponse, DefaultResponse, FreeSpaceResponse, GetTorrentRepsonse, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions
|
5
|
-
/**
|
6
|
-
* TODO: remove when hash is available on normalized torrent
|
7
|
-
* @deprecated
|
8
|
-
*/
|
9
|
-
export declare type TransmissionNormalizedTorrent = NormalizedTorrent & {
|
10
|
-
hash: string;
|
11
|
-
};
|
4
|
+
import { AddTorrentOptions, AddTorrentResponse, DefaultResponse, FreeSpaceResponse, GetTorrentRepsonse, NormalizedTorrentIds, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions } from './types';
|
12
5
|
export declare class Transmission implements TorrentClient {
|
13
6
|
config: TorrentSettings;
|
14
7
|
sessionId?: string;
|
15
8
|
constructor(options?: Partial<TorrentSettings>);
|
16
9
|
getSession(): Promise<SessionResponse>;
|
17
10
|
setSession(args: Partial<SessionArguments>): Promise<SessionResponse>;
|
18
|
-
queueTop(
|
19
|
-
queueBottom(
|
20
|
-
queueUp(
|
21
|
-
queueDown(
|
11
|
+
queueTop(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
12
|
+
queueBottom(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
13
|
+
queueUp(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
14
|
+
queueDown(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
22
15
|
freeSpace(path?: string): Promise<FreeSpaceResponse>;
|
23
|
-
pauseTorrent(
|
24
|
-
resumeTorrent(
|
25
|
-
verifyTorrent(
|
16
|
+
pauseTorrent(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
17
|
+
resumeTorrent(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
18
|
+
verifyTorrent(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
26
19
|
/**
|
27
20
|
* ask tracker for more peers
|
28
21
|
*/
|
29
|
-
reannounceTorrent(
|
30
|
-
moveTorrent(
|
22
|
+
reannounceTorrent(id: NormalizedTorrentIds): Promise<DefaultResponse>;
|
23
|
+
moveTorrent(id: NormalizedTorrentIds, location: string): Promise<DefaultResponse>;
|
31
24
|
/**
|
32
25
|
* Torrent Mutators
|
33
26
|
*/
|
34
|
-
setTorrent(
|
27
|
+
setTorrent(id: NormalizedTorrentIds, options?: Partial<SetTorrentOptions>): Promise<DefaultResponse>;
|
35
28
|
/**
|
36
29
|
* Renaming a Torrent's Path
|
37
30
|
*/
|
38
|
-
renamePath(
|
31
|
+
renamePath(id: NormalizedTorrentIds, options?: Partial<RenamePathOptions>): Promise<DefaultResponse>;
|
39
32
|
/**
|
40
33
|
* Removing a Torrent
|
41
34
|
*/
|
42
|
-
removeTorrent(
|
35
|
+
removeTorrent(id: NormalizedTorrentIds, removeData?: boolean): Promise<AddTorrentResponse>;
|
43
36
|
/**
|
44
37
|
* An alias for {@link Transmission.addMagnet}
|
45
38
|
*/
|
@@ -56,10 +49,11 @@ export declare class Transmission implements TorrentClient {
|
|
56
49
|
* @param torrent a string of file path or contents of the file as base64 string
|
57
50
|
*/
|
58
51
|
addTorrent(torrent: string | Buffer, options?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
|
59
|
-
normalizedAddTorrent(torrent: string | Buffer, options?: Partial<NormalizedAddTorrentOptions>): Promise<
|
60
|
-
getTorrent(id:
|
52
|
+
normalizedAddTorrent(torrent: string | Buffer, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
|
53
|
+
getTorrent(id: NormalizedTorrentIds): Promise<NormalizedTorrent>;
|
61
54
|
getAllData(): Promise<AllClientData>;
|
62
|
-
listTorrents(
|
55
|
+
listTorrents(id?: NormalizedTorrentIds, additionalFields?: string[]): Promise<GetTorrentRepsonse>;
|
63
56
|
request<T>(method: string, args?: any): Promise<Response<T>>;
|
57
|
+
private _handleNormalizedIds;
|
64
58
|
private _normalizeTorrentData;
|
65
59
|
}
|
package/dist/transmission.js
CHANGED
@@ -27,19 +27,23 @@ class Transmission {
|
|
27
27
|
const res = await this.request('session-set', args);
|
28
28
|
return res.body;
|
29
29
|
}
|
30
|
-
async queueTop(
|
30
|
+
async queueTop(id) {
|
31
|
+
const ids = this._handleNormalizedIds(id);
|
31
32
|
const res = await this.request('queue-move-top', { ids });
|
32
33
|
return res.body;
|
33
34
|
}
|
34
|
-
async queueBottom(
|
35
|
+
async queueBottom(id) {
|
36
|
+
const ids = this._handleNormalizedIds(id);
|
35
37
|
const res = await this.request('queue-move-bottom', { ids });
|
36
38
|
return res.body;
|
37
39
|
}
|
38
|
-
async queueUp(
|
40
|
+
async queueUp(id) {
|
41
|
+
const ids = this._handleNormalizedIds(id);
|
39
42
|
const res = await this.request('queue-move-up', { ids });
|
40
43
|
return res.body;
|
41
44
|
}
|
42
|
-
async queueDown(
|
45
|
+
async queueDown(id) {
|
46
|
+
const ids = this._handleNormalizedIds(id);
|
43
47
|
const res = await this.request('queue-move-down', { ids });
|
44
48
|
return res.body;
|
45
49
|
}
|
@@ -47,26 +51,31 @@ class Transmission {
|
|
47
51
|
const res = await this.request('free-space', { path });
|
48
52
|
return res.body;
|
49
53
|
}
|
50
|
-
async pauseTorrent(
|
54
|
+
async pauseTorrent(id) {
|
55
|
+
const ids = this._handleNormalizedIds(id);
|
51
56
|
const res = await this.request('torrent-stop', { ids });
|
52
57
|
return res.body;
|
53
58
|
}
|
54
|
-
async resumeTorrent(
|
59
|
+
async resumeTorrent(id) {
|
60
|
+
const ids = this._handleNormalizedIds(id);
|
55
61
|
const res = await this.request('torrent-start', { ids });
|
56
62
|
return res.body;
|
57
63
|
}
|
58
|
-
async verifyTorrent(
|
64
|
+
async verifyTorrent(id) {
|
65
|
+
const ids = this._handleNormalizedIds(id);
|
59
66
|
const res = await this.request('torrent-verify', { ids });
|
60
67
|
return res.body;
|
61
68
|
}
|
62
69
|
/**
|
63
70
|
* ask tracker for more peers
|
64
71
|
*/
|
65
|
-
async reannounceTorrent(
|
72
|
+
async reannounceTorrent(id) {
|
73
|
+
const ids = this._handleNormalizedIds(id);
|
66
74
|
const res = await this.request('torrent-reannounce', { ids });
|
67
75
|
return res.body;
|
68
76
|
}
|
69
|
-
async moveTorrent(
|
77
|
+
async moveTorrent(id, location) {
|
78
|
+
const ids = this._handleNormalizedIds(id);
|
70
79
|
const res = await this.request('torrent-set-location', {
|
71
80
|
ids,
|
72
81
|
move: true,
|
@@ -77,7 +86,8 @@ class Transmission {
|
|
77
86
|
/**
|
78
87
|
* Torrent Mutators
|
79
88
|
*/
|
80
|
-
async setTorrent(
|
89
|
+
async setTorrent(id, options = {}) {
|
90
|
+
const ids = this._handleNormalizedIds(id);
|
81
91
|
options.ids = ids;
|
82
92
|
const res = await this.request('torrent-set', options);
|
83
93
|
return res.body;
|
@@ -85,7 +95,8 @@ class Transmission {
|
|
85
95
|
/**
|
86
96
|
* Renaming a Torrent's Path
|
87
97
|
*/
|
88
|
-
async renamePath(
|
98
|
+
async renamePath(id, options = {}) {
|
99
|
+
const ids = this._handleNormalizedIds(id);
|
89
100
|
options.ids = ids;
|
90
101
|
const res = await this.request('torrent-rename-path', options);
|
91
102
|
return res.body;
|
@@ -93,7 +104,8 @@ class Transmission {
|
|
93
104
|
/**
|
94
105
|
* Removing a Torrent
|
95
106
|
*/
|
96
|
-
async removeTorrent(
|
107
|
+
async removeTorrent(id, removeData = true) {
|
108
|
+
const ids = this._handleNormalizedIds(id);
|
97
109
|
const res = await this.request('torrent-remove', {
|
98
110
|
ids,
|
99
111
|
'delete-local-data': removeData,
|
@@ -152,11 +164,11 @@ class Transmission {
|
|
152
164
|
torrent = Buffer.from(torrent);
|
153
165
|
}
|
154
166
|
const res = await this.addTorrent(torrent, torrentOptions);
|
155
|
-
const
|
167
|
+
const torrentHash = [res.arguments['torrent-added'].hashString];
|
156
168
|
if (options.label) {
|
157
|
-
await this.setTorrent(
|
169
|
+
await this.setTorrent(torrentHash, { labels: [options.label] });
|
158
170
|
}
|
159
|
-
return this.getTorrent(
|
171
|
+
return this.getTorrent(torrentHash);
|
160
172
|
}
|
161
173
|
async getTorrent(id) {
|
162
174
|
const result = await this.listTorrents(id);
|
@@ -186,7 +198,7 @@ class Transmission {
|
|
186
198
|
};
|
187
199
|
return results;
|
188
200
|
}
|
189
|
-
async listTorrents(
|
201
|
+
async listTorrents(id, additionalFields = []) {
|
190
202
|
const fields = [
|
191
203
|
'id',
|
192
204
|
'addedDate',
|
@@ -249,7 +261,8 @@ class Transmission {
|
|
249
261
|
...additionalFields,
|
250
262
|
];
|
251
263
|
const args = { fields };
|
252
|
-
if (
|
264
|
+
if (id) {
|
265
|
+
const ids = this._handleNormalizedIds(id);
|
253
266
|
args.ids = ids;
|
254
267
|
}
|
255
268
|
const res = await this.request('torrent-get', args);
|
@@ -293,6 +306,12 @@ class Transmission {
|
|
293
306
|
throw error;
|
294
307
|
}
|
295
308
|
}
|
309
|
+
_handleNormalizedIds(ids) {
|
310
|
+
if (typeof ids === 'string' && ids !== 'recently-active') {
|
311
|
+
return [ids];
|
312
|
+
}
|
313
|
+
return ids;
|
314
|
+
}
|
296
315
|
_normalizeTorrentData(torrent) {
|
297
316
|
var _a;
|
298
317
|
const dateAdded = new Date(torrent.addedDate * 1000).toISOString();
|
@@ -316,8 +335,7 @@ class Transmission {
|
|
316
335
|
state = shared_torrent_1.TorrentState.queued;
|
317
336
|
}
|
318
337
|
return {
|
319
|
-
id: torrent.
|
320
|
-
hash: torrent.hashString,
|
338
|
+
id: torrent.hashString,
|
321
339
|
name: torrent.name,
|
322
340
|
state,
|
323
341
|
isCompleted: torrent.leftUntilDone < 1,
|
package/dist/types.d.ts
CHANGED
@@ -39,12 +39,17 @@ export interface FreeSpaceResponse extends DefaultResponse {
|
|
39
39
|
/**
|
40
40
|
* "ids", which specifies which torrents to use.
|
41
41
|
* All torrents are used if the "ids" argument is omitted.
|
42
|
+
*
|
42
43
|
* "ids" should be one of the following:
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
44
|
+
* 1. an integer referring to a torrent id
|
45
|
+
* 2. a list of torrent id numbers, sha1 hash strings, or both
|
46
|
+
* 3. a string, "recently-active", for recently-active torrents
|
46
47
|
*/
|
47
48
|
export declare type TorrentIds = number | 'recently-active' | Array<number | string>;
|
49
|
+
/**
|
50
|
+
* Allows the user to pass a single hash, this will be converted to an array
|
51
|
+
*/
|
52
|
+
export declare type NormalizedTorrentIds = TorrentIds | string;
|
48
53
|
export interface GetTorrentRepsonse extends DefaultResponse {
|
49
54
|
arguments: {
|
50
55
|
removed: Torrent[];
|