@remote-app/transmission-client 0.1.3 → 0.22.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/README.md +90 -47
- package/dist/index.cjs +106 -0
- package/dist/index.d.cts +371 -0
- package/dist/index.d.mts +371 -0
- package/dist/index.mjs +99 -0
- package/dist/schemas.cjs +541 -0
- package/dist/schemas.d.cts +4657 -0
- package/dist/schemas.d.mts +4657 -0
- package/dist/schemas.mjs +506 -0
- package/dist/torrent-get-BosdT1jx.d.cts +195 -0
- package/dist/torrent-get-C1p73gUr.cjs +44 -0
- package/dist/torrent-get-D7xfEr_w.mjs +26 -0
- package/dist/torrent-get-Dqn7FoFh.d.mts +195 -0
- package/package.json +33 -7
- package/dist/client.d.ts +0 -10
- package/dist/client.js +0 -50
- package/dist/config.d.ts +0 -5
- package/dist/config.js +0 -1
- package/dist/error.d.ts +0 -9
- package/dist/error.js +0 -15
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -3
- package/dist/rpc-call.d.ts +0 -51
- package/dist/rpc-call.js +0 -1
- package/dist/rpc-calls/free-space.d.ts +0 -7
- package/dist/rpc-calls/free-space.js +0 -1
- package/dist/rpc-calls/index.d.ts +0 -14
- package/dist/rpc-calls/index.js +0 -1
- package/dist/rpc-calls/session-get.d.ts +0 -61
- package/dist/rpc-calls/session-get.js +0 -1
- package/dist/rpc-calls/session-set.d.ts +0 -2
- package/dist/rpc-calls/session-set.js +0 -1
- package/dist/rpc-calls/session-stats.d.ts +0 -24
- package/dist/rpc-calls/session-stats.js +0 -1
- package/dist/rpc-calls/torrent-add.d.ts +0 -24
- package/dist/rpc-calls/torrent-add.js +0 -1
- package/dist/rpc-calls/torrent-get.d.ts +0 -166
- package/dist/rpc-calls/torrent-get.js +0 -10
- package/dist/rpc-calls/torrent-reannounce.d.ts +0 -1
- package/dist/rpc-calls/torrent-reannounce.js +0 -1
- package/dist/rpc-calls/torrent-remove.d.ts +0 -4
- package/dist/rpc-calls/torrent-remove.js +0 -1
- package/dist/rpc-calls/torrent-set-location.d.ts +0 -5
- package/dist/rpc-calls/torrent-set-location.js +0 -1
- package/dist/rpc-calls/torrent-set.d.ts +0 -25
- package/dist/rpc-calls/torrent-set.js +0 -1
- package/dist/rpc-calls/torrent-start-now.d.ts +0 -1
- package/dist/rpc-calls/torrent-start-now.js +0 -1
- package/dist/rpc-calls/torrent-start.d.ts +0 -1
- package/dist/rpc-calls/torrent-start.js +0 -1
- package/dist/rpc-calls/torrent-stop.d.ts +0 -1
- package/dist/rpc-calls/torrent-stop.js +0 -1
- package/dist/rpc-calls/torrent-verify.d.ts +0 -1
- package/dist/rpc-calls/torrent-verify.js +0 -1
- package/dist/rpc-calls/utils.d.ts +0 -6
- package/dist/rpc-calls/utils.js +0 -1
package/README.md
CHANGED
|
@@ -2,60 +2,103 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
A lightweight Transmission RPC client.
|
|
5
|
+
A lightweight [Transmission](https://transmissionbt.com/) RPC client for Node.js and React Native.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm install @remote-app/transmission-client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import TransmissionClient from "@remote-app/transmission-client";
|
|
17
|
+
|
|
18
|
+
const client = new TransmissionClient({
|
|
19
|
+
url: "http://localhost:9091/transmission/rpc",
|
|
20
|
+
username: "admin",
|
|
21
|
+
password: "admin",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Get all torrents
|
|
25
|
+
const response = await client.request({
|
|
26
|
+
method: "torrent-get",
|
|
27
|
+
arguments: {
|
|
28
|
+
fields: ["id", "name", "status", "percentDone", "rateDownload"],
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(response.arguments.torrents);
|
|
33
|
+
|
|
34
|
+
// Add a torrent
|
|
35
|
+
await client.request({
|
|
36
|
+
method: "torrent-add",
|
|
37
|
+
arguments: { filename: "magnet:?xt=urn:btih:..." },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Update session settings
|
|
41
|
+
await client.request({
|
|
42
|
+
method: "session-set",
|
|
43
|
+
arguments: { "alt-speed-down": 500 },
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The client handles Transmission's CSRF protection automatically (409 session-id negotiation).
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
The client exposes a single typed `request` method. The `method` field determines which arguments are accepted and what the response looks like.
|
|
14
52
|
|
|
15
53
|
### Torrent methods
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- Torrent mutator
|
|
23
|
-
- [x] torrent-set
|
|
24
|
-
- Torrent accessor
|
|
25
|
-
- [x] torrent-get
|
|
26
|
-
- Torrent addition
|
|
27
|
-
- [x] torrent-add
|
|
28
|
-
- Torrent removal
|
|
29
|
-
- [x] torrent-remove
|
|
30
|
-
- Move torrent
|
|
31
|
-
- [x] torrent-set-location
|
|
32
|
-
- Renaming torrent
|
|
33
|
-
- [ ] torrent-rename-path
|
|
54
|
+
|
|
55
|
+
- `torrent-start` / `torrent-start-now` / `torrent-stop`
|
|
56
|
+
- `torrent-verify` / `torrent-reannounce`
|
|
57
|
+
- `torrent-set` / `torrent-get`
|
|
58
|
+
- `torrent-add` / `torrent-remove`
|
|
59
|
+
- `torrent-set-location` / `torrent-rename-path`
|
|
34
60
|
|
|
35
61
|
### Session methods
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
- `session-get` / `session-set`
|
|
64
|
+
- `session-stats` / `session-close`
|
|
65
|
+
|
|
66
|
+
### Queue methods
|
|
67
|
+
|
|
68
|
+
- `queue-move-top` / `queue-move-up` / `queue-move-down` / `queue-move-bottom`
|
|
69
|
+
|
|
70
|
+
### Other
|
|
71
|
+
|
|
72
|
+
- `blocklist-update`
|
|
73
|
+
- `port-test`
|
|
74
|
+
- `free-space`
|
|
75
|
+
- `group-get` / `group-set`
|
|
76
|
+
|
|
77
|
+
## Error handling
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import TransmissionClient, {
|
|
81
|
+
HTTPError,
|
|
82
|
+
TransmissionError,
|
|
83
|
+
ResponseParseError,
|
|
84
|
+
} from "@remote-app/transmission-client";
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await client.request({ method: "session-stats" });
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof HTTPError) {
|
|
90
|
+
// Non-200 HTTP response (e.g. 401 Unauthorized)
|
|
91
|
+
console.error(error.status, error.message);
|
|
92
|
+
} else if (error instanceof TransmissionError) {
|
|
93
|
+
// Transmission returned result !== "success"
|
|
94
|
+
console.error(error.message);
|
|
95
|
+
} else if (error instanceof ResponseParseError) {
|
|
96
|
+
// Response body was not valid JSON
|
|
97
|
+
console.error(error.status, error.body);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_torrent_get = require('./torrent-get-C1p73gUr.cjs');
|
|
3
|
+
let base_64 = require("base-64");
|
|
4
|
+
|
|
5
|
+
//#region src/error.ts
|
|
6
|
+
var HTTPError = class extends Error {
|
|
7
|
+
constructor(status, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.name = "HTTPError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var TransmissionError = class extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.message = message;
|
|
18
|
+
this.name = "TransmissionError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var ResponseParseError = class extends Error {
|
|
22
|
+
constructor(status, body) {
|
|
23
|
+
super("The server returned an unexpected response");
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.name = "ResponseParseError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/client.ts
|
|
32
|
+
var TransmissionClient = class {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.session = null;
|
|
36
|
+
this.sessionPromise = null;
|
|
37
|
+
}
|
|
38
|
+
authHeader() {
|
|
39
|
+
if (!this.config.username && !this.config.password) return null;
|
|
40
|
+
return `Basic ${(0, base_64.encode)(`${this.config.username ?? ""}:${this.config.password ?? ""}`)}`;
|
|
41
|
+
}
|
|
42
|
+
async ensureSession() {
|
|
43
|
+
if (this.session) return;
|
|
44
|
+
if (this.sessionPromise) return await this.sessionPromise;
|
|
45
|
+
this.sessionPromise = this.fetchSession();
|
|
46
|
+
try {
|
|
47
|
+
await this.sessionPromise;
|
|
48
|
+
} finally {
|
|
49
|
+
this.sessionPromise = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async fetchSession() {
|
|
53
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
54
|
+
const auth = this.authHeader();
|
|
55
|
+
if (auth) headers.set("Authorization", auth);
|
|
56
|
+
const response = await fetch(new Request(this.config.url, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers,
|
|
59
|
+
body: JSON.stringify({ method: "session-stats" })
|
|
60
|
+
}));
|
|
61
|
+
if (response.status !== 409) {
|
|
62
|
+
if (!response.ok) throw new HTTPError(response.status, response.statusText);
|
|
63
|
+
throw new HTTPError(response.status, "Expected Transmission session negotiation response");
|
|
64
|
+
}
|
|
65
|
+
const nextSession = response.headers.get("x-transmission-session-id");
|
|
66
|
+
if (!nextSession) throw new HTTPError(409, "Missing x-transmission-session-id header");
|
|
67
|
+
this.session = nextSession;
|
|
68
|
+
}
|
|
69
|
+
async request(req, retry = true) {
|
|
70
|
+
await this.ensureSession();
|
|
71
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
72
|
+
headers.set("x-transmission-session-id", this.session);
|
|
73
|
+
const auth = this.authHeader();
|
|
74
|
+
if (auth) headers.set("Authorization", auth);
|
|
75
|
+
const request = new Request(this.config.url, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers,
|
|
78
|
+
body: JSON.stringify(req)
|
|
79
|
+
});
|
|
80
|
+
const response = await fetch(request);
|
|
81
|
+
if (response.status === 409 && retry) {
|
|
82
|
+
this.session = null;
|
|
83
|
+
await this.ensureSession();
|
|
84
|
+
return await this.request(req, false);
|
|
85
|
+
}
|
|
86
|
+
if (!response.ok) throw new HTTPError(response.status, response.statusText);
|
|
87
|
+
const text = await response.text();
|
|
88
|
+
let json;
|
|
89
|
+
try {
|
|
90
|
+
json = JSON.parse(text);
|
|
91
|
+
} catch {
|
|
92
|
+
throw new ResponseParseError(response.status, text);
|
|
93
|
+
}
|
|
94
|
+
if (json && json.result !== "success") throw new TransmissionError(json.result);
|
|
95
|
+
return json;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
exports.HTTPError = HTTPError;
|
|
101
|
+
exports.Mode = require_torrent_get.Mode;
|
|
102
|
+
exports.Priority = require_torrent_get.Priority;
|
|
103
|
+
exports.ResponseParseError = ResponseParseError;
|
|
104
|
+
exports.TorrentStatus = require_torrent_get.TorrentStatus;
|
|
105
|
+
exports.TransmissionError = TransmissionError;
|
|
106
|
+
exports.default = TransmissionClient;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { a as ResponseFor$1, c as TorrentStatus, i as Response$8, l as Identifiers, n as Priority, o as TorrentField, r as Request$17, s as TorrentForFields, t as Mode } from "./torrent-get-BosdT1jx.cjs";
|
|
2
|
+
import { BandwidthGroup, BlocklistUpdateRequest, BlocklistUpdateResponse, FreeSpaceRequest, FreeSpaceResponse, GroupGetRequest, GroupGetResponse, GroupSetRequest, PortTestRequest, PortTestResponse, QueueMoveBottomRequest, QueueMoveDownRequest, QueueMoveTopRequest, QueueMoveUpRequest, SessionCloseRequest, SessionGetRequest, SessionGetResponse, SessionSetRequest, SessionStatsResponse, Torrent, TorrentAddRequest, TorrentAddResponse, TorrentGetRequest, TorrentGetResponse, TorrentReannounceRequest, TorrentRemoveRequest, TorrentRenamePathRequest, TorrentRenamePathResponse, TorrentSetLocationRequest, TorrentSetRequest, TorrentStartNowRequest, TorrentStartRequest, TorrentStopRequest, TorrentVerifyRequest } from "./schemas.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/rpc-calls/session-get.d.ts
|
|
5
|
+
type Units = {
|
|
6
|
+
"speed-units": string[];
|
|
7
|
+
"speed-bytes": number;
|
|
8
|
+
"size-units": string[];
|
|
9
|
+
"size-bytes": number;
|
|
10
|
+
"memory-units": string[];
|
|
11
|
+
"memory-bytes": number;
|
|
12
|
+
};
|
|
13
|
+
type Response$7 = {
|
|
14
|
+
"alt-speed-down"?: number;
|
|
15
|
+
"alt-speed-enabled"?: boolean;
|
|
16
|
+
"alt-speed-time-begin"?: number;
|
|
17
|
+
"alt-speed-time-enabled"?: boolean;
|
|
18
|
+
"alt-speed-time-end"?: number;
|
|
19
|
+
"alt-speed-time-day"?: number;
|
|
20
|
+
"alt-speed-up"?: number;
|
|
21
|
+
"blocklist-url"?: string;
|
|
22
|
+
"blocklist-enabled"?: boolean;
|
|
23
|
+
"blocklist-size"?: number;
|
|
24
|
+
"cache-size-mb"?: number;
|
|
25
|
+
"config-dir"?: string;
|
|
26
|
+
"default-trackers"?: string;
|
|
27
|
+
"dht-enabled"?: boolean;
|
|
28
|
+
"download-dir"?: string;
|
|
29
|
+
"download-dir-free-space"?: number;
|
|
30
|
+
"download-queue-size"?: number;
|
|
31
|
+
"download-queue-enabled"?: boolean;
|
|
32
|
+
encryption?: string;
|
|
33
|
+
"idle-seeding-limit"?: number;
|
|
34
|
+
"idle-seeding-limit-enabled"?: boolean;
|
|
35
|
+
"incomplete-dir"?: string;
|
|
36
|
+
"incomplete-dir-enabled"?: boolean;
|
|
37
|
+
"lpd-enabled"?: boolean;
|
|
38
|
+
"peer-limit-global"?: number;
|
|
39
|
+
"peer-limit-per-torrent"?: number;
|
|
40
|
+
"pex-enabled"?: boolean;
|
|
41
|
+
"peer-port"?: number;
|
|
42
|
+
"peer-port-random-on-start"?: boolean;
|
|
43
|
+
"port-forwarding-enabled"?: boolean;
|
|
44
|
+
"queue-stalled-enabled"?: boolean;
|
|
45
|
+
"queue-stalled-minutes"?: number;
|
|
46
|
+
"rename-partial-files"?: boolean;
|
|
47
|
+
reqq?: number;
|
|
48
|
+
"rpc-version"?: number;
|
|
49
|
+
"rpc-version-minimum"?: number;
|
|
50
|
+
"rpc-version-semver"?: string;
|
|
51
|
+
"script-torrent-added-enabled"?: boolean;
|
|
52
|
+
"script-torrent-added-filename"?: string;
|
|
53
|
+
"script-torrent-done-filename"?: string;
|
|
54
|
+
"script-torrent-done-enabled"?: boolean;
|
|
55
|
+
"script-torrent-done-seeding-enabled"?: boolean;
|
|
56
|
+
"script-torrent-done-seeding-filename"?: string;
|
|
57
|
+
seedRatioLimit?: number;
|
|
58
|
+
seedRatioLimited?: boolean;
|
|
59
|
+
"seed-queue-size"?: number;
|
|
60
|
+
"seed-queue-enabled"?: boolean;
|
|
61
|
+
"sequential-download"?: boolean;
|
|
62
|
+
"session-id"?: string;
|
|
63
|
+
"speed-limit-down"?: number;
|
|
64
|
+
"speed-limit-down-enabled"?: boolean;
|
|
65
|
+
"speed-limit-up"?: number;
|
|
66
|
+
"speed-limit-up-enabled"?: boolean;
|
|
67
|
+
"start-added-torrents"?: boolean;
|
|
68
|
+
"trash-original-torrent-files"?: boolean;
|
|
69
|
+
units?: Units;
|
|
70
|
+
"utp-enabled"?: boolean;
|
|
71
|
+
version?: string;
|
|
72
|
+
};
|
|
73
|
+
type SessionGetField = keyof Response$7;
|
|
74
|
+
type SelectedSessionFields<F extends readonly SessionGetField[]> = { [K in F[number]]-?: NonNullable<Response$7[K]> };
|
|
75
|
+
type IsTuple<T extends readonly unknown[]> = number extends T["length"] ? false : true;
|
|
76
|
+
type SessionGetForFields<F extends readonly SessionGetField[]> = IsTuple<F> extends true ? SelectedSessionFields<F> : Response$7;
|
|
77
|
+
type ResponseFor<F extends readonly SessionGetField[]> = SessionGetForFields<F>;
|
|
78
|
+
type Request$16<F extends readonly SessionGetField[] = readonly SessionGetField[]> = {
|
|
79
|
+
fields?: F;
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/rpc-calls/session-set.d.ts
|
|
83
|
+
type Request$15 = Partial<Response$7>;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/rpc-calls/session-stats.d.ts
|
|
86
|
+
type CurrentStats = {
|
|
87
|
+
uploadedBytes: number;
|
|
88
|
+
downloadedBytes: number;
|
|
89
|
+
filesAdded: number;
|
|
90
|
+
sessionCount: number;
|
|
91
|
+
secondsActive: number;
|
|
92
|
+
};
|
|
93
|
+
type CumulativeStats = {
|
|
94
|
+
uploadedBytes: number;
|
|
95
|
+
downloadedBytes: number;
|
|
96
|
+
filesAdded: number;
|
|
97
|
+
sessionCount: number;
|
|
98
|
+
secondsActive: number;
|
|
99
|
+
};
|
|
100
|
+
type Response$6 = {
|
|
101
|
+
activeTorrentCount: number;
|
|
102
|
+
downloadSpeed: number;
|
|
103
|
+
pausedTorrentCount: number;
|
|
104
|
+
torrentCount: number;
|
|
105
|
+
uploadSpeed: number;
|
|
106
|
+
"cumulative-stats": CumulativeStats;
|
|
107
|
+
"current-stats": CurrentStats;
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/rpc-calls/session-close.d.ts
|
|
111
|
+
type Request$14 = never;
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/rpc-calls/free-space.d.ts
|
|
114
|
+
type Response$5 = {
|
|
115
|
+
path: string;
|
|
116
|
+
"size-bytes": number;
|
|
117
|
+
};
|
|
118
|
+
type Request$13 = {
|
|
119
|
+
path: string;
|
|
120
|
+
};
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/rpc-calls/torrent-set.d.ts
|
|
123
|
+
type Request$12 = Identifiers & {
|
|
124
|
+
bandwidthPriority?: Priority;
|
|
125
|
+
downloadLimit?: number;
|
|
126
|
+
downloadLimited?: boolean;
|
|
127
|
+
"files-wanted"?: number[];
|
|
128
|
+
"files-unwanted"?: number[];
|
|
129
|
+
honorsSessionLimits?: boolean;
|
|
130
|
+
labels?: string[];
|
|
131
|
+
location?: string;
|
|
132
|
+
"peer-limit"?: number;
|
|
133
|
+
"priority-high"?: number[];
|
|
134
|
+
"priority-low"?: number[];
|
|
135
|
+
"priority-normal"?: number[];
|
|
136
|
+
queuePosition?: number;
|
|
137
|
+
seedIdleLimit?: number;
|
|
138
|
+
seedIdleMode?: Mode;
|
|
139
|
+
seedRatioLimit?: number;
|
|
140
|
+
seedRatioMode?: Mode;
|
|
141
|
+
trackerAdd?: string[];
|
|
142
|
+
trackerRemove?: number[];
|
|
143
|
+
trackerReplace?: Array<{
|
|
144
|
+
id: number;
|
|
145
|
+
announce: string;
|
|
146
|
+
}>;
|
|
147
|
+
trackerList?: string;
|
|
148
|
+
group?: string;
|
|
149
|
+
sequentialDownload?: boolean;
|
|
150
|
+
uploadLimit?: number;
|
|
151
|
+
uploadLimited?: boolean;
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/rpc-calls/torrent-add.d.ts
|
|
155
|
+
type optionals = {
|
|
156
|
+
cookies?: string;
|
|
157
|
+
"download-dir"?: string;
|
|
158
|
+
labels?: string[];
|
|
159
|
+
paused?: boolean;
|
|
160
|
+
"peer-limit"?: number;
|
|
161
|
+
bandwidthPriority?: number;
|
|
162
|
+
"files-wanted"?: number[];
|
|
163
|
+
"files-unwanted"?: number[];
|
|
164
|
+
"priority-high"?: number[];
|
|
165
|
+
"priority-low"?: number[];
|
|
166
|
+
"priority-normal"?: number[];
|
|
167
|
+
"sequential-download"?: boolean;
|
|
168
|
+
};
|
|
169
|
+
type Request$11 = ({
|
|
170
|
+
filename: string;
|
|
171
|
+
} | {
|
|
172
|
+
metainfo: string;
|
|
173
|
+
}) & optionals;
|
|
174
|
+
type Response$4 = {
|
|
175
|
+
"torrent-added": Pick<Response$8["torrents"][number], "id" | "name" | "hashString">[];
|
|
176
|
+
} | {
|
|
177
|
+
"torrent-duplicate": Pick<Response$8["torrents"][number], "id" | "name" | "hashString">[];
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/rpc-calls/torrent-remove.d.ts
|
|
181
|
+
type Request$10 = Identifiers & {
|
|
182
|
+
"delete-local-data"?: boolean;
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/rpc-calls/torrent-set-location.d.ts
|
|
186
|
+
type Request$9 = Identifiers & {
|
|
187
|
+
location: string;
|
|
188
|
+
move?: boolean;
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/rpc-calls/torrent-rename-path.d.ts
|
|
192
|
+
type Request$8 = Identifiers & {
|
|
193
|
+
path: string;
|
|
194
|
+
name: string;
|
|
195
|
+
};
|
|
196
|
+
type Response$3 = {
|
|
197
|
+
path: string;
|
|
198
|
+
name: string;
|
|
199
|
+
id: number;
|
|
200
|
+
};
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/rpc-calls/queue-move-top.d.ts
|
|
203
|
+
type Request$7 = Identifiers;
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/rpc-calls/queue-move-up.d.ts
|
|
206
|
+
type Request$6 = Identifiers;
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/rpc-calls/queue-move-down.d.ts
|
|
209
|
+
type Request$5 = Identifiers;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/rpc-calls/queue-move-bottom.d.ts
|
|
212
|
+
type Request$4 = Identifiers;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/rpc-calls/blocklist-update.d.ts
|
|
215
|
+
type Request$3 = never;
|
|
216
|
+
type Response$2 = {
|
|
217
|
+
"blocklist-size": number;
|
|
218
|
+
};
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/rpc-calls/port-test.d.ts
|
|
221
|
+
type Request$2 = {
|
|
222
|
+
ipProtocol?: "ipv4" | "ipv6";
|
|
223
|
+
};
|
|
224
|
+
type Response$1 = {
|
|
225
|
+
"port-is-open": boolean;
|
|
226
|
+
ipProtocol?: "ipv4" | "ipv6";
|
|
227
|
+
};
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/rpc-calls/group-get.d.ts
|
|
230
|
+
type BandwidthGroup$1 = {
|
|
231
|
+
honorsSessionLimits: boolean;
|
|
232
|
+
name: string;
|
|
233
|
+
"speed-limit-down-enabled": boolean;
|
|
234
|
+
"speed-limit-down": number;
|
|
235
|
+
"speed-limit-up-enabled": boolean;
|
|
236
|
+
"speed-limit-up": number;
|
|
237
|
+
};
|
|
238
|
+
type Request$1 = {
|
|
239
|
+
group?: string | string[];
|
|
240
|
+
};
|
|
241
|
+
type Response = {
|
|
242
|
+
group: BandwidthGroup$1[];
|
|
243
|
+
};
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/rpc-calls/group-set.d.ts
|
|
246
|
+
type Request = {
|
|
247
|
+
honorsSessionLimits?: boolean;
|
|
248
|
+
name: string;
|
|
249
|
+
"speed-limit-down-enabled"?: boolean;
|
|
250
|
+
"speed-limit-down"?: number;
|
|
251
|
+
"speed-limit-up-enabled"?: boolean;
|
|
252
|
+
"speed-limit-up"?: number;
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/rpc-call.d.ts
|
|
256
|
+
type SessionMethods = "session-get" | "session-set" | "session-stats" | "session-close" | "free-space";
|
|
257
|
+
type TorrentMethods = "torrent-start" | "torrent-start-now" | "torrent-stop" | "torrent-verify" | "torrent-reannounce" | "torrent-set" | "torrent-get" | "torrent-add" | "torrent-remove" | "torrent-set-location" | "torrent-rename-path";
|
|
258
|
+
type QueueMethods = "queue-move-top" | "queue-move-up" | "queue-move-down" | "queue-move-bottom";
|
|
259
|
+
type OtherMethods = "blocklist-update" | "port-test" | "group-get" | "group-set";
|
|
260
|
+
type Methods = SessionMethods | TorrentMethods | QueueMethods | OtherMethods;
|
|
261
|
+
type RPCRequest<M, T> = {
|
|
262
|
+
method: M;
|
|
263
|
+
arguments?: T;
|
|
264
|
+
tag?: number;
|
|
265
|
+
};
|
|
266
|
+
type RPCResponse<A> = {
|
|
267
|
+
result: string;
|
|
268
|
+
arguments: A;
|
|
269
|
+
tag?: number;
|
|
270
|
+
};
|
|
271
|
+
type MethodRequest = {
|
|
272
|
+
"session-get": Request$16;
|
|
273
|
+
"session-set": Request$15;
|
|
274
|
+
"session-stats": never;
|
|
275
|
+
"session-close": Request$14;
|
|
276
|
+
"free-space": Request$13;
|
|
277
|
+
"torrent-start": Identifiers;
|
|
278
|
+
"torrent-start-now": Identifiers;
|
|
279
|
+
"torrent-stop": Identifiers;
|
|
280
|
+
"torrent-verify": Identifiers;
|
|
281
|
+
"torrent-reannounce": Identifiers;
|
|
282
|
+
"torrent-remove": Request$10;
|
|
283
|
+
"torrent-set-location": Request$9;
|
|
284
|
+
"torrent-get": Request$17;
|
|
285
|
+
"torrent-add": Request$11;
|
|
286
|
+
"torrent-set": Request$12;
|
|
287
|
+
"torrent-rename-path": Request$8;
|
|
288
|
+
"queue-move-top": Request$7;
|
|
289
|
+
"queue-move-up": Request$6;
|
|
290
|
+
"queue-move-down": Request$5;
|
|
291
|
+
"queue-move-bottom": Request$4;
|
|
292
|
+
"blocklist-update": Request$3;
|
|
293
|
+
"port-test": Request$2;
|
|
294
|
+
"group-get": Request$1;
|
|
295
|
+
"group-set": Request;
|
|
296
|
+
};
|
|
297
|
+
type MethodResponse = {
|
|
298
|
+
"session-get": Response$7;
|
|
299
|
+
"session-set": void;
|
|
300
|
+
"session-stats": Response$6;
|
|
301
|
+
"session-close": void;
|
|
302
|
+
"free-space": Response$5;
|
|
303
|
+
"torrent-start": void;
|
|
304
|
+
"torrent-start-now": void;
|
|
305
|
+
"torrent-stop": void;
|
|
306
|
+
"torrent-verify": void;
|
|
307
|
+
"torrent-reannounce": void;
|
|
308
|
+
"torrent-remove": void;
|
|
309
|
+
"torrent-set-location": void;
|
|
310
|
+
"torrent-get": Response$8;
|
|
311
|
+
"torrent-add": Response$4;
|
|
312
|
+
"torrent-set": void;
|
|
313
|
+
"torrent-rename-path": Response$3;
|
|
314
|
+
"queue-move-top": void;
|
|
315
|
+
"queue-move-up": void;
|
|
316
|
+
"queue-move-down": void;
|
|
317
|
+
"queue-move-bottom": void;
|
|
318
|
+
"blocklist-update": Response$2;
|
|
319
|
+
"port-test": Response$1;
|
|
320
|
+
"group-get": Response;
|
|
321
|
+
"group-set": void;
|
|
322
|
+
};
|
|
323
|
+
type RequestForMethod<M extends Methods> = RPCRequest<M, MethodRequest[M]>;
|
|
324
|
+
type AnyRequest = { [K in Methods]: RequestForMethod<K> }[Methods];
|
|
325
|
+
type MethodResponseForRequest<M extends Methods, Req extends RequestForMethod<M>> = M extends "torrent-get" ? Req extends {
|
|
326
|
+
arguments: {
|
|
327
|
+
fields: infer F extends readonly TorrentField[];
|
|
328
|
+
};
|
|
329
|
+
} ? ResponseFor$1<F> : Response$8 : M extends "session-get" ? Req extends {
|
|
330
|
+
arguments: {
|
|
331
|
+
fields: infer F extends readonly SessionGetField[];
|
|
332
|
+
};
|
|
333
|
+
} ? ResponseFor<F> : Response$7 : MethodResponse[M];
|
|
334
|
+
type ResponseForRequest<Req extends AnyRequest> = Req extends RequestForMethod<infer M extends Methods> ? RPCResponse<MethodResponseForRequest<M, Req>> : never;
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/error.d.ts
|
|
337
|
+
declare class HTTPError extends Error {
|
|
338
|
+
readonly status: number;
|
|
339
|
+
readonly message: string;
|
|
340
|
+
constructor(status: number, message: string);
|
|
341
|
+
}
|
|
342
|
+
declare class TransmissionError extends Error {
|
|
343
|
+
readonly message: string;
|
|
344
|
+
constructor(message: string);
|
|
345
|
+
}
|
|
346
|
+
declare class ResponseParseError extends Error {
|
|
347
|
+
readonly status: number;
|
|
348
|
+
readonly body: string;
|
|
349
|
+
constructor(status: number, body: string);
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/config.d.ts
|
|
353
|
+
type TransmissionConfig = {
|
|
354
|
+
url: string;
|
|
355
|
+
username?: string;
|
|
356
|
+
password?: string;
|
|
357
|
+
};
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/client.d.ts
|
|
360
|
+
declare class TransmissionClient {
|
|
361
|
+
private config;
|
|
362
|
+
private session;
|
|
363
|
+
private sessionPromise;
|
|
364
|
+
constructor(config: TransmissionConfig);
|
|
365
|
+
private authHeader;
|
|
366
|
+
private ensureSession;
|
|
367
|
+
private fetchSession;
|
|
368
|
+
request<Req extends AnyRequest>(req: Req, retry?: boolean): Promise<ResponseForRequest<Req>>;
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { type BandwidthGroup, type BlocklistUpdateRequest, type BlocklistUpdateResponse, type FreeSpaceRequest, type FreeSpaceResponse, type GroupGetRequest, type GroupGetResponse, type GroupSetRequest, HTTPError, type Methods, Mode, type PortTestRequest, type PortTestResponse, Priority, type QueueMoveBottomRequest, type QueueMoveDownRequest, type QueueMoveTopRequest, type QueueMoveUpRequest, ResponseParseError, type SessionCloseRequest, type SessionGetField, type SessionGetForFields, type SessionGetRequest, type SessionGetResponse, type ResponseFor as SessionGetResponseFor, type SessionSetRequest, type SessionStatsResponse, type Torrent, type TorrentAddRequest, type TorrentAddResponse, type TorrentField, type TorrentForFields, type TorrentGetRequest, type TorrentGetResponse, type ResponseFor$1 as TorrentGetResponseFor, type TorrentReannounceRequest, type TorrentRemoveRequest, type TorrentRenamePathRequest, type TorrentRenamePathResponse, type TorrentSetLocationRequest, type TorrentSetRequest, type TorrentStartNowRequest, type TorrentStartRequest, TorrentStatus, type TorrentStopRequest, type TorrentVerifyRequest, TransmissionError, TransmissionClient as default };
|