@ctrl/transmission 3.0.0 → 4.1.1
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/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/{transmission.d.ts → src/transmission.d.ts} +2 -2
- package/dist/{transmission.js → src/transmission.js} +48 -34
- package/dist/{types.d.ts → src/types.d.ts} +0 -0
- package/dist/src/types.js +1 -0
- package/package.json +25 -31
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -14
- package/dist/types.js +0 -2
@@ -1,7 +1,7 @@
|
|
1
|
-
/// <reference types="node" />
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
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, NormalizedTorrentIds, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions } from './types';
|
4
|
+
import { AddTorrentOptions, AddTorrentResponse, DefaultResponse, FreeSpaceResponse, GetTorrentRepsonse, NormalizedTorrentIds, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions } from './types.js';
|
5
5
|
export declare class Transmission implements TorrentClient {
|
6
6
|
config: TorrentSettings;
|
7
7
|
sessionId?: string;
|
@@ -1,13 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
|
6
|
-
exports.Transmission = void 0;
|
7
|
-
const fs_1 = require("fs");
|
8
|
-
const got_1 = __importDefault(require("got"));
|
9
|
-
const shared_torrent_1 = require("@ctrl/shared-torrent");
|
10
|
-
const url_join_1 = require("@ctrl/url-join");
|
1
|
+
import { existsSync, readFileSync } from 'fs';
|
2
|
+
import got from 'got';
|
3
|
+
import { magnetDecode } from '@ctrl/magnet-link';
|
4
|
+
import { TorrentState, } from '@ctrl/shared-torrent';
|
5
|
+
import { urlJoin } from '@ctrl/url-join';
|
11
6
|
const defaults = {
|
12
7
|
baseUrl: 'http://localhost:9091/',
|
13
8
|
path: '/transmission/rpc',
|
@@ -15,8 +10,20 @@ const defaults = {
|
|
15
10
|
password: '',
|
16
11
|
timeout: 5000,
|
17
12
|
};
|
18
|
-
class Transmission {
|
13
|
+
export class Transmission {
|
19
14
|
constructor(options = {}) {
|
15
|
+
Object.defineProperty(this, "config", {
|
16
|
+
enumerable: true,
|
17
|
+
configurable: true,
|
18
|
+
writable: true,
|
19
|
+
value: void 0
|
20
|
+
});
|
21
|
+
Object.defineProperty(this, "sessionId", {
|
22
|
+
enumerable: true,
|
23
|
+
configurable: true,
|
24
|
+
writable: true,
|
25
|
+
value: void 0
|
26
|
+
});
|
20
27
|
this.config = { ...defaults, ...options };
|
21
28
|
}
|
22
29
|
async getSession() {
|
@@ -145,8 +152,8 @@ class Transmission {
|
|
145
152
|
...options,
|
146
153
|
};
|
147
154
|
if (typeof torrent === 'string') {
|
148
|
-
args.metainfo =
|
149
|
-
? Buffer.from(
|
155
|
+
args.metainfo = existsSync(torrent)
|
156
|
+
? Buffer.from(readFileSync(torrent)).toString('base64')
|
150
157
|
: Buffer.from(torrent, 'base64').toString('base64');
|
151
158
|
}
|
152
159
|
else {
|
@@ -160,11 +167,21 @@ class Transmission {
|
|
160
167
|
if (options.startPaused) {
|
161
168
|
torrentOptions.paused = true;
|
162
169
|
}
|
163
|
-
|
164
|
-
|
170
|
+
let torrentHash;
|
171
|
+
if (typeof torrent === 'string' && torrent.startsWith('magnet:')) {
|
172
|
+
torrentHash = magnetDecode(torrent).infoHash;
|
173
|
+
if (!torrentHash) {
|
174
|
+
throw new Error('Magnet did not contain hash');
|
175
|
+
}
|
176
|
+
await this.addMagnet(torrent, torrentOptions);
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
if (!Buffer.isBuffer(torrent)) {
|
180
|
+
torrent = Buffer.from(torrent);
|
181
|
+
}
|
182
|
+
const res = await this.addTorrent(torrent, torrentOptions);
|
183
|
+
torrentHash = res.arguments['torrent-added'].hashString;
|
165
184
|
}
|
166
|
-
const res = await this.addTorrent(torrent, torrentOptions);
|
167
|
-
const torrentHash = [res.arguments['torrent-added'].hashString];
|
168
185
|
if (options.label) {
|
169
186
|
await this.setTorrent(torrentHash, { labels: [options.label] });
|
170
187
|
}
|
@@ -269,7 +286,6 @@ class Transmission {
|
|
269
286
|
return res.body;
|
270
287
|
}
|
271
288
|
async request(method, args = {}) {
|
272
|
-
var _a, _b, _c;
|
273
289
|
if (!this.sessionId && method !== 'session-get') {
|
274
290
|
await this.getSession();
|
275
291
|
}
|
@@ -277,27 +293,27 @@ class Transmission {
|
|
277
293
|
'X-Transmission-Session-Id': this.sessionId,
|
278
294
|
};
|
279
295
|
if (this.config.username || this.config.password) {
|
280
|
-
const str = `${
|
296
|
+
const str = `${this.config.username ?? ''}:${this.config.password ?? ''}`;
|
281
297
|
headers.Authorization = 'Basic ' + Buffer.from(str).toString('base64');
|
282
298
|
}
|
283
|
-
const url =
|
299
|
+
const url = urlJoin(this.config.baseUrl, this.config.path);
|
284
300
|
try {
|
285
|
-
const res = await
|
301
|
+
const res = await got.post(url, {
|
286
302
|
json: {
|
287
303
|
method,
|
288
304
|
arguments: args,
|
289
305
|
},
|
290
306
|
headers,
|
291
|
-
retry: 0,
|
307
|
+
retry: { limit: 0 },
|
292
308
|
// allow proxy agent
|
293
|
-
|
294
|
-
timeout: this.config.timeout,
|
309
|
+
timeout: { request: this.config.timeout },
|
295
310
|
responseType: 'json',
|
311
|
+
...(this.config.agent ? { agent: this.config.agent } : {}),
|
296
312
|
});
|
297
313
|
return res;
|
298
314
|
}
|
299
315
|
catch (error) {
|
300
|
-
if (
|
316
|
+
if (error?.response?.statusCode === 409) {
|
301
317
|
this.sessionId = error.response.headers['x-transmission-session-id'];
|
302
318
|
// eslint-disable-next-line no-return-await
|
303
319
|
return await this.request(method, args);
|
@@ -313,26 +329,25 @@ class Transmission {
|
|
313
329
|
return ids;
|
314
330
|
}
|
315
331
|
_normalizeTorrentData(torrent) {
|
316
|
-
var _a;
|
317
332
|
const dateAdded = new Date(torrent.addedDate * 1000).toISOString();
|
318
333
|
const dateCompleted = new Date(torrent.doneDate * 1000).toISOString();
|
319
334
|
// normalize state to enum
|
320
335
|
// https://github.com/transmission/transmission/blob/c11f2870fd18ff781ca06ce84b6d43541f3293dd/web/javascript/torrent.js#L18
|
321
|
-
let state =
|
336
|
+
let state = TorrentState.unknown;
|
322
337
|
if (torrent.status === 6) {
|
323
|
-
state =
|
338
|
+
state = TorrentState.seeding;
|
324
339
|
}
|
325
340
|
else if (torrent.status === 4) {
|
326
|
-
state =
|
341
|
+
state = TorrentState.downloading;
|
327
342
|
}
|
328
343
|
else if (torrent.status === 0) {
|
329
|
-
state =
|
344
|
+
state = TorrentState.paused;
|
330
345
|
}
|
331
346
|
else if (torrent.status === 2) {
|
332
|
-
state =
|
347
|
+
state = TorrentState.checking;
|
333
348
|
}
|
334
349
|
else if (torrent.status === 3 || torrent.status === 5) {
|
335
|
-
state =
|
350
|
+
state = TorrentState.queued;
|
336
351
|
}
|
337
352
|
return {
|
338
353
|
id: torrent.hashString,
|
@@ -344,7 +359,7 @@ class Transmission {
|
|
344
359
|
ratio: torrent.uploadRatio,
|
345
360
|
dateAdded,
|
346
361
|
dateCompleted,
|
347
|
-
label:
|
362
|
+
label: torrent.labels?.length ? torrent.labels[0] : undefined,
|
348
363
|
savePath: torrent.downloadDir,
|
349
364
|
uploadSpeed: torrent.rateUpload,
|
350
365
|
downloadSpeed: torrent.rateDownload,
|
@@ -361,4 +376,3 @@ class Transmission {
|
|
361
376
|
};
|
362
377
|
}
|
363
378
|
}
|
364
|
-
exports.Transmission = Transmission;
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/transmission",
|
3
|
-
"version": "
|
3
|
+
"version": "4.1.1",
|
4
4
|
"description": "TypeScript api wrapper for transmission using got",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -9,58 +9,52 @@
|
|
9
9
|
"transmission",
|
10
10
|
"typescript"
|
11
11
|
],
|
12
|
-
"
|
13
|
-
"
|
12
|
+
"type": "module",
|
13
|
+
"main": "./dist/src/index.js",
|
14
|
+
"typings": "./dist/src/index.d.ts",
|
14
15
|
"files": [
|
15
|
-
"dist"
|
16
|
+
"dist/src"
|
16
17
|
],
|
17
18
|
"sideEffects": false,
|
18
19
|
"scripts": {
|
19
20
|
"lint": "eslint --ext .ts .",
|
20
21
|
"lint:fix": "eslint --fix --ext .ts .",
|
21
22
|
"prepare": "npm run build",
|
22
|
-
"build": "tsc
|
23
|
+
"build": "tsc",
|
23
24
|
"build:docs": "typedoc",
|
24
|
-
"test": "
|
25
|
-
"test:watch": "
|
26
|
-
"test:ci": "
|
25
|
+
"test": "vitest run",
|
26
|
+
"test:watch": "vitest",
|
27
|
+
"test:ci": "vitest run --coverage"
|
27
28
|
},
|
28
29
|
"dependencies": {
|
29
|
-
"@ctrl/
|
30
|
-
"
|
31
|
-
"@ctrl/url-join": "^
|
30
|
+
"@ctrl/magnet-link": "^3.1.0",
|
31
|
+
"@ctrl/shared-torrent": "^4.1.1",
|
32
|
+
"@ctrl/url-join": "^2.0.0",
|
33
|
+
"got": "^12.1.0"
|
32
34
|
},
|
33
35
|
"devDependencies": {
|
34
|
-
"@
|
35
|
-
"@
|
36
|
-
"@
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"typedoc": "0.22.11",
|
43
|
-
"typescript": "4.5.5"
|
36
|
+
"@ctrl/eslint-config": "3.4.4",
|
37
|
+
"@sindresorhus/tsconfig": "3.0.1",
|
38
|
+
"@types/node": "17.0.38",
|
39
|
+
"c8": "7.11.3",
|
40
|
+
"p-wait-for": "4.1.0",
|
41
|
+
"typedoc": "0.22.17",
|
42
|
+
"typescript": "4.7.2",
|
43
|
+
"vitest": "0.13.1"
|
44
44
|
},
|
45
45
|
"jest": {
|
46
46
|
"testEnvironment": "node",
|
47
47
|
"coverageProvider": "v8"
|
48
48
|
},
|
49
|
-
"babel": {
|
50
|
-
"presets": [
|
51
|
-
"@babel/preset-typescript"
|
52
|
-
],
|
53
|
-
"plugins": [
|
54
|
-
"@babel/plugin-transform-modules-commonjs"
|
55
|
-
]
|
56
|
-
},
|
57
49
|
"publishConfig": {
|
58
50
|
"access": "public"
|
59
51
|
},
|
60
52
|
"release": {
|
61
|
-
"
|
53
|
+
"branches": [
|
54
|
+
"master"
|
55
|
+
]
|
62
56
|
},
|
63
57
|
"engines": {
|
64
|
-
"node": ">=
|
58
|
+
"node": ">=14.16"
|
65
59
|
}
|
66
60
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
-
}) : (function(o, m, k, k2) {
|
6
|
-
if (k2 === undefined) k2 = k;
|
7
|
-
o[k2] = m[k];
|
8
|
-
}));
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
|
-
};
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
__exportStar(require("./transmission"), exports);
|
14
|
-
__exportStar(require("./types"), exports);
|
package/dist/types.js
DELETED