@ctrl/qbittorrent 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/README.md +1 -1
- package/dist/src/qbittorrent.d.ts +5 -1
- package/dist/src/qbittorrent.js +17 -8
- package/dist/src/types.d.ts +8 -8
- package/dist/src/types.js +12 -12
- package/package.json +21 -32
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# qBittorrent [](https://www.npmjs.com/package/@ctrl/qbittorrent) [](https://circleci.com/gh/scttcper/qbittorrent) [](https://codecov.io/gh/scttcper/qbittorrent)
|
1
|
+
# qBittorrent [](https://www.npmjs.com/package/@ctrl/qbittorrent) [](https://circleci.com/gh/scttcper/qbittorrent) [](https://codecov.io/gh/scttcper/qbittorrent)
|
2
2
|
|
3
3
|
> TypeScript api wrapper for [qBittorrent](https://www.qbittorrent.org/) using [got](https://github.com/sindresorhus/got)
|
4
4
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/// <reference types="node" />
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { Options as GotOptions, Response } from 'got';
|
3
3
|
import { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentSettings } from '@ctrl/shared-torrent';
|
4
4
|
import { AddMagnetOptions, AddTorrentOptions, BuildInfo, Preferences, Torrent, TorrentCategories, TorrentFile, TorrentFilePriority, TorrentFilters, TorrentPieceState, TorrentProperties, TorrentTrackers, WebSeed } from './types.js';
|
@@ -160,6 +160,10 @@ export declare class QBittorrent implements TorrentClient {
|
|
160
160
|
* @param name new name to be assigned to the file
|
161
161
|
*/
|
162
162
|
renameFile(hash: string, id: number, name: string): Promise<boolean>;
|
163
|
+
/**
|
164
|
+
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
|
165
|
+
*/
|
166
|
+
renameFolder(hash: string, oldPath: string, newPath: string): Promise<boolean>;
|
163
167
|
/**
|
164
168
|
* @param urls URLs separated with newlines
|
165
169
|
* @param options
|
package/dist/src/qbittorrent.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
1
2
|
/* eslint-disable @typescript-eslint/ban-types */
|
2
3
|
import { existsSync } from 'fs';
|
3
4
|
import { URLSearchParams } from 'url';
|
@@ -373,7 +374,6 @@ export class QBittorrent {
|
|
373
374
|
return true;
|
374
375
|
}
|
375
376
|
async addTorrent(torrent, options = {}) {
|
376
|
-
var _a, _b;
|
377
377
|
const form = new FormData();
|
378
378
|
// remove options.filename, not used in form
|
379
379
|
if (options.filename) {
|
@@ -382,7 +382,7 @@ export class QBittorrent {
|
|
382
382
|
const type = { type: 'application/x-bittorrent' };
|
383
383
|
if (typeof torrent === 'string') {
|
384
384
|
if (existsSync(torrent)) {
|
385
|
-
const file = await fileFromPath(torrent,
|
385
|
+
const file = await fileFromPath(torrent, options.filename ?? 'torrent', type);
|
386
386
|
form.set('file', file);
|
387
387
|
}
|
388
388
|
else {
|
@@ -390,7 +390,7 @@ export class QBittorrent {
|
|
390
390
|
}
|
391
391
|
}
|
392
392
|
else {
|
393
|
-
const file = new File([torrent],
|
393
|
+
const file = new File([torrent], options.filename ?? 'torrent', type);
|
394
394
|
form.set('file', file);
|
395
395
|
}
|
396
396
|
if (options) {
|
@@ -449,6 +449,17 @@ export class QBittorrent {
|
|
449
449
|
await this.request('/torrents/renameFile', 'POST', undefined, form, undefined, false);
|
450
450
|
return true;
|
451
451
|
}
|
452
|
+
/**
|
453
|
+
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
|
454
|
+
*/
|
455
|
+
async renameFolder(hash, oldPath, newPath) {
|
456
|
+
const form = new FormData();
|
457
|
+
form.append('hash', hash);
|
458
|
+
form.append('oldPath', oldPath);
|
459
|
+
form.append('newPath', newPath);
|
460
|
+
await this.request('/torrents/renameFolder', 'POST', undefined, form, undefined, false);
|
461
|
+
return true;
|
462
|
+
}
|
452
463
|
/**
|
453
464
|
* @param urls URLs separated with newlines
|
454
465
|
* @param options
|
@@ -542,14 +553,13 @@ export class QBittorrent {
|
|
542
553
|
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#login}
|
543
554
|
*/
|
544
555
|
async login() {
|
545
|
-
var _a, _b;
|
546
556
|
const url = urlJoin(this.config.baseUrl, this.config.path, '/auth/login');
|
547
557
|
const res = await got({
|
548
558
|
url,
|
549
559
|
method: 'POST',
|
550
560
|
form: {
|
551
|
-
username:
|
552
|
-
password:
|
561
|
+
username: this.config.username ?? '',
|
562
|
+
password: this.config.password ?? '',
|
553
563
|
},
|
554
564
|
followRedirect: false,
|
555
565
|
retry: { limit: 0 },
|
@@ -575,7 +585,6 @@ export class QBittorrent {
|
|
575
585
|
}
|
576
586
|
// eslint-disable-next-line max-params
|
577
587
|
async request(path, method, params = {}, body, form, headers = {}, json = true) {
|
578
|
-
var _a;
|
579
588
|
if (!this._sid || !this._exp || this._exp.getTime() < new Date().getTime()) {
|
580
589
|
const authed = await this.login();
|
581
590
|
if (!authed) {
|
@@ -588,7 +597,7 @@ export class QBittorrent {
|
|
588
597
|
resolveBodyOnly: false,
|
589
598
|
method,
|
590
599
|
headers: {
|
591
|
-
Cookie: `SID=${
|
600
|
+
Cookie: `SID=${this._sid ?? ''}`,
|
592
601
|
...headers,
|
593
602
|
},
|
594
603
|
retry: { limit: 0 },
|
package/dist/src/types.d.ts
CHANGED
@@ -424,21 +424,21 @@ export declare enum TorrentTrackerStatus {
|
|
424
424
|
*/
|
425
425
|
Disabled = 0,
|
426
426
|
/**
|
427
|
-
* Tracker has been contacted
|
427
|
+
* Tracker has not been contacted yet
|
428
428
|
*/
|
429
|
-
|
429
|
+
Waiting = 1,
|
430
430
|
/**
|
431
|
-
* Tracker
|
431
|
+
* Tracker has been contacted and is working
|
432
432
|
*/
|
433
|
-
|
433
|
+
Working = 2,
|
434
434
|
/**
|
435
|
-
* Tracker
|
435
|
+
* Tracker is updating
|
436
436
|
*/
|
437
|
-
|
437
|
+
Updating = 3,
|
438
438
|
/**
|
439
|
-
* Tracker has
|
439
|
+
* Tracker has been contacted, but it is not working (or doesn't send proper replies)
|
440
440
|
*/
|
441
|
-
|
441
|
+
Errored = 4
|
442
442
|
}
|
443
443
|
export interface WebSeed {
|
444
444
|
/**
|
package/dist/src/types.js
CHANGED
@@ -77,7 +77,7 @@ export var TorrentState;
|
|
77
77
|
* Torrent data files is missing
|
78
78
|
*/
|
79
79
|
TorrentState["MissingFiles"] = "missingFiles";
|
80
|
-
})(TorrentState || (TorrentState = {}));
|
80
|
+
})(TorrentState = TorrentState || (TorrentState = {}));
|
81
81
|
export var TorrentTrackerStatus;
|
82
82
|
(function (TorrentTrackerStatus) {
|
83
83
|
/**
|
@@ -85,22 +85,22 @@ export var TorrentTrackerStatus;
|
|
85
85
|
*/
|
86
86
|
TorrentTrackerStatus[TorrentTrackerStatus["Disabled"] = 0] = "Disabled";
|
87
87
|
/**
|
88
|
-
* Tracker has been contacted
|
88
|
+
* Tracker has not been contacted yet
|
89
89
|
*/
|
90
|
-
TorrentTrackerStatus[TorrentTrackerStatus["
|
90
|
+
TorrentTrackerStatus[TorrentTrackerStatus["Waiting"] = 1] = "Waiting";
|
91
91
|
/**
|
92
|
-
* Tracker
|
92
|
+
* Tracker has been contacted and is working
|
93
93
|
*/
|
94
|
-
TorrentTrackerStatus[TorrentTrackerStatus["
|
94
|
+
TorrentTrackerStatus[TorrentTrackerStatus["Working"] = 2] = "Working";
|
95
95
|
/**
|
96
|
-
* Tracker
|
96
|
+
* Tracker is updating
|
97
97
|
*/
|
98
|
-
TorrentTrackerStatus[TorrentTrackerStatus["
|
98
|
+
TorrentTrackerStatus[TorrentTrackerStatus["Updating"] = 3] = "Updating";
|
99
99
|
/**
|
100
|
-
* Tracker has
|
100
|
+
* Tracker has been contacted, but it is not working (or doesn't send proper replies)
|
101
101
|
*/
|
102
|
-
TorrentTrackerStatus[TorrentTrackerStatus["
|
103
|
-
})(TorrentTrackerStatus || (TorrentTrackerStatus = {}));
|
102
|
+
TorrentTrackerStatus[TorrentTrackerStatus["Errored"] = 4] = "Errored";
|
103
|
+
})(TorrentTrackerStatus = TorrentTrackerStatus || (TorrentTrackerStatus = {}));
|
104
104
|
export var TorrentFilePriority;
|
105
105
|
(function (TorrentFilePriority) {
|
106
106
|
/**
|
@@ -119,7 +119,7 @@ export var TorrentFilePriority;
|
|
119
119
|
* Maximal priority
|
120
120
|
*/
|
121
121
|
TorrentFilePriority[TorrentFilePriority["MaxPriority"] = 7] = "MaxPriority";
|
122
|
-
})(TorrentFilePriority || (TorrentFilePriority = {}));
|
122
|
+
})(TorrentFilePriority = TorrentFilePriority || (TorrentFilePriority = {}));
|
123
123
|
export var TorrentPieceState;
|
124
124
|
(function (TorrentPieceState) {
|
125
125
|
/**
|
@@ -134,4 +134,4 @@ export var TorrentPieceState;
|
|
134
134
|
* Already downloaded
|
135
135
|
*/
|
136
136
|
TorrentPieceState[TorrentPieceState["Downloaded"] = 2] = "Downloaded";
|
137
|
-
})(TorrentPieceState || (TorrentPieceState = {}));
|
137
|
+
})(TorrentPieceState = TorrentPieceState || (TorrentPieceState = {}));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/qbittorrent",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.1.0",
|
4
4
|
"description": "TypeScript api wrapper for qbittorrent using got",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -8,7 +8,7 @@
|
|
8
8
|
"homepage": "https://qbittorrent.vercel.app",
|
9
9
|
"type": "module",
|
10
10
|
"main": "./dist/src/index.js",
|
11
|
-
"
|
11
|
+
"types": "./dist/src/index.d.ts",
|
12
12
|
"files": [
|
13
13
|
"dist/src"
|
14
14
|
],
|
@@ -26,45 +26,34 @@
|
|
26
26
|
"prepare": "npm run build",
|
27
27
|
"build": "tsc",
|
28
28
|
"build:docs": "typedoc",
|
29
|
-
"test": "
|
30
|
-
"test:watch": "
|
31
|
-
"test:ci": "
|
29
|
+
"test": "vitest run",
|
30
|
+
"test:watch": "vitest",
|
31
|
+
"test:ci": "vitest run --coverage --reporter=junit --outputFile=./junit.xml"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@ctrl/magnet-link": "^3.1.
|
35
|
-
"@ctrl/shared-torrent": "^4.1.
|
36
|
-
"@ctrl/torrent-file": "^2.0.
|
37
|
-
"@ctrl/url-join": "^2.0.
|
38
|
-
"formdata-node": "^4.3.
|
39
|
-
"got": "^12.0
|
34
|
+
"@ctrl/magnet-link": "^3.1.1",
|
35
|
+
"@ctrl/shared-torrent": "^4.1.1",
|
36
|
+
"@ctrl/torrent-file": "^2.0.2",
|
37
|
+
"@ctrl/url-join": "^2.0.2",
|
38
|
+
"formdata-node": "^4.3.3",
|
39
|
+
"got": "^12.1.0",
|
40
40
|
"tough-cookie": "^4.0.0"
|
41
41
|
},
|
42
42
|
"devDependencies": {
|
43
|
-
"@ctrl/eslint-config": "3.4.
|
44
|
-
"@sindresorhus/tsconfig": "
|
45
|
-
"@types/node": "
|
43
|
+
"@ctrl/eslint-config": "3.4.6",
|
44
|
+
"@sindresorhus/tsconfig": "3.0.1",
|
45
|
+
"@types/node": "18.0.3",
|
46
46
|
"@types/tough-cookie": "4.0.2",
|
47
|
-
"
|
48
|
-
"c8": "7.11.2",
|
47
|
+
"c8": "7.11.3",
|
49
48
|
"p-wait-for": "4.1.0",
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"typescript": "4.6.4"
|
54
|
-
},
|
55
|
-
"ava": {
|
56
|
-
"files": [
|
57
|
-
"test/**/*.spec.ts"
|
58
|
-
],
|
59
|
-
"extensions": {
|
60
|
-
"ts": "module"
|
61
|
-
},
|
62
|
-
"nodeArguments": [
|
63
|
-
"--loader=ts-node/esm"
|
64
|
-
]
|
49
|
+
"typedoc": "0.23.7",
|
50
|
+
"typescript": "4.7.4",
|
51
|
+
"vitest": "0.18.0"
|
65
52
|
},
|
66
53
|
"release": {
|
67
|
-
"
|
54
|
+
"branches": [
|
55
|
+
"master"
|
56
|
+
]
|
68
57
|
},
|
69
58
|
"engines": {
|
70
59
|
"node": ">=14.16"
|