@ctrl/transmission 4.0.0 → 4.1.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/src/transmission.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
2
2
|
import got from 'got';
|
3
|
+
import { magnetDecode } from '@ctrl/magnet-link';
|
3
4
|
import { TorrentState, } from '@ctrl/shared-torrent';
|
4
5
|
import { urlJoin } from '@ctrl/url-join';
|
5
6
|
const defaults = {
|
@@ -166,11 +167,21 @@ export class Transmission {
|
|
166
167
|
if (options.startPaused) {
|
167
168
|
torrentOptions.paused = true;
|
168
169
|
}
|
169
|
-
|
170
|
-
|
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;
|
171
184
|
}
|
172
|
-
const res = await this.addTorrent(torrent, torrentOptions);
|
173
|
-
const torrentHash = [res.arguments['torrent-added'].hashString];
|
174
185
|
if (options.label) {
|
175
186
|
await this.setTorrent(torrentHash, { labels: [options.label] });
|
176
187
|
}
|
@@ -40,6 +40,12 @@ describe('Transmission', () => {
|
|
40
40
|
const res = await client.addMagnet(magnet);
|
41
41
|
expect(res.result).toBe('success');
|
42
42
|
});
|
43
|
+
it('should add normalized magnet link', async () => {
|
44
|
+
const magnet = 'magnet:?xt=urn:btih:B0B81206633C42874173D22E564D293DAEFC45E2&dn=Ubuntu+11+10+Alternate+Amd64+Iso&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.open-internet.nl%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.si%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Fdenis.stalker.upeer.me%3A6969%2Fannounce&tr=udp%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce';
|
45
|
+
const client = new Transmission({ baseUrl });
|
46
|
+
const res = await client.normalizedAddTorrent(magnet);
|
47
|
+
expect(res.id).toBeTruthy();
|
48
|
+
});
|
43
49
|
it('should add torrent from file buffer', async () => {
|
44
50
|
const transmission = new Transmission({ baseUrl });
|
45
51
|
const res = await transmission.addTorrent(fs.readFileSync(torrentFile));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/transmission",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.1.0",
|
4
4
|
"description": "TypeScript api wrapper for transmission using got",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -27,7 +27,8 @@
|
|
27
27
|
"test:ci": "vitest run --coverage"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"@ctrl/
|
30
|
+
"@ctrl/magnet-link": "^3.1.0",
|
31
|
+
"@ctrl/shared-torrent": "^4.1.1",
|
31
32
|
"@ctrl/url-join": "^2.0.0",
|
32
33
|
"got": "^12.1.0"
|
33
34
|
},
|