@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 CHANGED
@@ -1,4 +1,4 @@
1
- # qBittorrent [![npm](https://badgen.net/npm/v/@ctrl/qbittorrent)](https://www.npmjs.com/package/@ctrl/qbittorrent) [![CircleCI](https://badgen.net/circleci/github/scttcper/qbittorrent)](https://circleci.com/gh/scttcper/qbittorrent) [![coverage](https://badgen.net/codecov/c/github/scttcper/qbittorrent)](https://codecov.io/gh/scttcper/qbittorrent) [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/qbittorrent)](https://bundlephobia.com/result?p=@ctrl/qbittorrent)
1
+ # qBittorrent [![npm](https://badgen.net/npm/v/@ctrl/qbittorrent)](https://www.npmjs.com/package/@ctrl/qbittorrent) [![CircleCI](https://badgen.net/circleci/github/scttcper/qbittorrent)](https://circleci.com/gh/scttcper/qbittorrent) [![coverage](https://badgen.net/codecov/c/github/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
@@ -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, (_a = options.filename) !== null && _a !== void 0 ? _a : 'torrent', type);
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], (_b = options.filename) !== null && _b !== void 0 ? _b : 'torrent', type);
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: (_a = this.config.username) !== null && _a !== void 0 ? _a : '',
552
- password: (_b = this.config.password) !== null && _b !== void 0 ? _b : '',
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=${(_a = this._sid) !== null && _a !== void 0 ? _a : ''}`,
600
+ Cookie: `SID=${this._sid ?? ''}`,
592
601
  ...headers,
593
602
  },
594
603
  retry: { limit: 0 },
@@ -424,21 +424,21 @@ export declare enum TorrentTrackerStatus {
424
424
  */
425
425
  Disabled = 0,
426
426
  /**
427
- * Tracker has been contacted and is working
427
+ * Tracker has not been contacted yet
428
428
  */
429
- Working = 1,
429
+ Waiting = 1,
430
430
  /**
431
- * Tracker is currently being updated
431
+ * Tracker has been contacted and is working
432
432
  */
433
- Updating = 2,
433
+ Working = 2,
434
434
  /**
435
- * Tracker has been contacted, but it is not working (or doesn't send proper replies)
435
+ * Tracker is updating
436
436
  */
437
- Errored = 3,
437
+ Updating = 3,
438
438
  /**
439
- * Tracker has not been contacted yet
439
+ * Tracker has been contacted, but it is not working (or doesn't send proper replies)
440
440
  */
441
- Waiting = 4
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 and is working
88
+ * Tracker has not been contacted yet
89
89
  */
90
- TorrentTrackerStatus[TorrentTrackerStatus["Working"] = 1] = "Working";
90
+ TorrentTrackerStatus[TorrentTrackerStatus["Waiting"] = 1] = "Waiting";
91
91
  /**
92
- * Tracker is currently being updated
92
+ * Tracker has been contacted and is working
93
93
  */
94
- TorrentTrackerStatus[TorrentTrackerStatus["Updating"] = 2] = "Updating";
94
+ TorrentTrackerStatus[TorrentTrackerStatus["Working"] = 2] = "Working";
95
95
  /**
96
- * Tracker has been contacted, but it is not working (or doesn't send proper replies)
96
+ * Tracker is updating
97
97
  */
98
- TorrentTrackerStatus[TorrentTrackerStatus["Errored"] = 3] = "Errored";
98
+ TorrentTrackerStatus[TorrentTrackerStatus["Updating"] = 3] = "Updating";
99
99
  /**
100
- * Tracker has not been contacted yet
100
+ * Tracker has been contacted, but it is not working (or doesn't send proper replies)
101
101
  */
102
- TorrentTrackerStatus[TorrentTrackerStatus["Waiting"] = 4] = "Waiting";
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.0.0",
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
- "typings": "./dist/src/index.d.ts",
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": "ava",
30
- "test:watch": "ava --watch",
31
- "test:ci": "c8 --reporter=text --reporter=lcov ava --tap | tap-junit -o junit -n test-result.xml"
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.0",
35
- "@ctrl/shared-torrent": "^4.1.0",
36
- "@ctrl/torrent-file": "^2.0.1",
37
- "@ctrl/url-join": "^2.0.0",
38
- "formdata-node": "^4.3.2",
39
- "got": "^12.0.4",
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.2",
44
- "@sindresorhus/tsconfig": "2.0.0",
45
- "@types/node": "17.0.31",
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
- "ava": "4.2.0",
48
- "c8": "7.11.2",
47
+ "c8": "7.11.3",
49
48
  "p-wait-for": "4.1.0",
50
- "tap-junit": "5.0.2",
51
- "ts-node": "10.7.0",
52
- "typedoc": "0.22.15",
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
- "branch": "master"
54
+ "branches": [
55
+ "master"
56
+ ]
68
57
  },
69
58
  "engines": {
70
59
  "node": ">=14.16"