@ctrl/transmission 5.0.1 → 6.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.d.ts +5 -6
- package/dist/src/transmission.js +7 -6
- package/package.json +22 -14
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
import { FetchResponse } from 'ofetch';
|
1
|
+
import { ofetch } from 'ofetch';
|
3
2
|
import type { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentSettings } from '@ctrl/shared-torrent';
|
4
3
|
import type { AddTorrentOptions, AddTorrentResponse, DefaultResponse, FreeSpaceResponse, GetTorrentRepsonse, NormalizedTorrentIds, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions } from './types.js';
|
5
4
|
export declare class Transmission implements TorrentClient {
|
@@ -46,13 +45,13 @@ export declare class Transmission implements TorrentClient {
|
|
46
45
|
addMagnet(url: string, options?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
|
47
46
|
/**
|
48
47
|
* Adding a torrent
|
49
|
-
* @param torrent a
|
48
|
+
* @param torrent a stream of file content or contents of the file as base64 string
|
50
49
|
*/
|
51
|
-
addTorrent(torrent: string |
|
52
|
-
normalizedAddTorrent(torrent: string |
|
50
|
+
addTorrent(torrent: string | Uint8Array, options?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
|
51
|
+
normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
|
53
52
|
getTorrent(id: NormalizedTorrentIds): Promise<NormalizedTorrent>;
|
54
53
|
getAllData(): Promise<AllClientData>;
|
55
54
|
listTorrents(id?: NormalizedTorrentIds, additionalFields?: string[]): Promise<GetTorrentRepsonse>;
|
56
|
-
request<T>(method: string, args?: any): Promise<
|
55
|
+
request<T>(method: string, args?: any): Promise<ReturnType<typeof ofetch.raw<T>>>;
|
57
56
|
private _handleNormalizedIds;
|
58
57
|
}
|
package/dist/src/transmission.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { FetchError, ofetch } from 'ofetch';
|
2
2
|
import { joinURL } from 'ufo';
|
3
|
+
import { uint8ArrayToBase64 } from 'uint8array-extras';
|
3
4
|
import { magnetDecode } from '@ctrl/magnet-link';
|
4
5
|
import { normalizeTorrentData } from './normalizeTorrentData.js';
|
5
6
|
const defaults = {
|
@@ -132,7 +133,7 @@ export class Transmission {
|
|
132
133
|
}
|
133
134
|
/**
|
134
135
|
* Adding a torrent
|
135
|
-
* @param torrent a
|
136
|
+
* @param torrent a stream of file content or contents of the file as base64 string
|
136
137
|
*/
|
137
138
|
async addTorrent(torrent, options = {}) {
|
138
139
|
const args = {
|
@@ -141,10 +142,10 @@ export class Transmission {
|
|
141
142
|
...options,
|
142
143
|
};
|
143
144
|
if (typeof torrent === 'string') {
|
144
|
-
args.metainfo =
|
145
|
+
args.metainfo = torrent;
|
145
146
|
}
|
146
147
|
else {
|
147
|
-
args.metainfo = torrent
|
148
|
+
args.metainfo = uint8ArrayToBase64(torrent);
|
148
149
|
}
|
149
150
|
const res = await this.request('torrent-add', args);
|
150
151
|
return res._data;
|
@@ -183,13 +184,13 @@ export class Transmission {
|
|
183
184
|
}
|
184
185
|
async getAllData() {
|
185
186
|
const listTorrents = await this.listTorrents();
|
186
|
-
const torrents = listTorrents.arguments.torrents.map(
|
187
|
+
const torrents = listTorrents.arguments.torrents.map(n => normalizeTorrentData(n));
|
187
188
|
const labels = [];
|
188
189
|
for (const torrent of torrents) {
|
189
190
|
if (!torrent.label) {
|
190
191
|
continue;
|
191
192
|
}
|
192
|
-
const existing = labels.find(
|
193
|
+
const existing = labels.find(n => n.id === torrent.label);
|
193
194
|
if (existing) {
|
194
195
|
existing.count += 1;
|
195
196
|
continue;
|
@@ -314,7 +315,7 @@ export class Transmission {
|
|
314
315
|
catch (error) {
|
315
316
|
if (error instanceof FetchError && error.response.status === 409) {
|
316
317
|
this.sessionId = error.response.headers.get('x-transmission-session-id');
|
317
|
-
// eslint-disable-next-line no-return-await
|
318
|
+
// eslint-disable-next-line no-return-await, @typescript-eslint/return-await
|
318
319
|
return await this.request(method, args);
|
319
320
|
}
|
320
321
|
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/transmission",
|
3
|
-
"version": "
|
3
|
+
"version": "6.1.0",
|
4
4
|
"description": "TypeScript api wrapper for transmission using got",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -17,8 +17,12 @@
|
|
17
17
|
],
|
18
18
|
"sideEffects": false,
|
19
19
|
"scripts": {
|
20
|
-
"lint": "
|
21
|
-
"lint:
|
20
|
+
"lint": "pnpm run '/^(lint:biome|lint:eslint)$/'",
|
21
|
+
"lint:biome": "biome check .",
|
22
|
+
"lint:eslint": "eslint .",
|
23
|
+
"lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
|
24
|
+
"lint:eslint:fix": "eslint . --fix",
|
25
|
+
"lint:biome:fix": "biome check . --apply",
|
22
26
|
"prepare": "npm run build",
|
23
27
|
"build": "tsc",
|
24
28
|
"build:docs": "typedoc",
|
@@ -27,20 +31,24 @@
|
|
27
31
|
"test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
|
28
32
|
},
|
29
33
|
"dependencies": {
|
30
|
-
"@ctrl/magnet-link": "^
|
31
|
-
"@ctrl/shared-torrent": "^
|
32
|
-
"ofetch": "^1.3.
|
33
|
-
"ufo": "^1.3
|
34
|
+
"@ctrl/magnet-link": "^4.0.2",
|
35
|
+
"@ctrl/shared-torrent": "^6.0.0",
|
36
|
+
"ofetch": "^1.3.4",
|
37
|
+
"ufo": "^1.5.3",
|
38
|
+
"uint8array-extras": "^1.2.0"
|
34
39
|
},
|
35
40
|
"devDependencies": {
|
36
|
-
"@
|
37
|
-
"@
|
38
|
-
"@
|
39
|
-
"@
|
41
|
+
"@biomejs/biome": "1.8.3",
|
42
|
+
"@ctrl/eslint-config-biome": "3.1.3",
|
43
|
+
"@ctrl/magnet-link": "^4.0.2",
|
44
|
+
"@ctrl/shared-torrent": "^6.0.0",
|
45
|
+
"@sindresorhus/tsconfig": "6.0.0",
|
46
|
+
"@types/node": "20.14.9",
|
47
|
+
"@vitest/coverage-v8": "1.6.0",
|
40
48
|
"p-wait-for": "5.0.2",
|
41
|
-
"typedoc": "0.
|
42
|
-
"typescript": "5.
|
43
|
-
"vitest": "
|
49
|
+
"typedoc": "0.26.3",
|
50
|
+
"typescript": "5.5.3",
|
51
|
+
"vitest": "1.6.0"
|
44
52
|
},
|
45
53
|
"publishConfig": {
|
46
54
|
"access": "public",
|