@ctrl/qbittorrent 8.1.0 → 8.3.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.
@@ -21,6 +21,10 @@ export declare class QBittorrent implements TorrentClient {
21
21
  */
22
22
  getAppVersion(): Promise<string>;
23
23
  getApiVersion(): Promise<string>;
24
+ /**
25
+ * Get default save path
26
+ */
27
+ getDefaultSavePath(): Promise<string>;
24
28
  /**
25
29
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-build-info}
26
30
  */
@@ -64,7 +68,7 @@ export declare class QBittorrent implements TorrentClient {
64
68
  */
65
69
  torrentWebSeeds(hash: string): Promise<WebSeed[]>;
66
70
  torrentFiles(hash: string): Promise<TorrentFile[]>;
67
- setFilePriority(hash: string, fileIds: string | string[], priority: TorrentFilePriority): Promise<TorrentFile[]>;
71
+ setFilePriority(hash: string, fileIds: string | string[], priority: TorrentFilePriority): Promise<boolean>;
68
72
  /**
69
73
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-states}
70
74
  */
@@ -154,10 +158,10 @@ export declare class QBittorrent implements TorrentClient {
154
158
  normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
155
159
  /**
156
160
  * @param hash Hash for desired torrent
157
- * @param id id of the file to be renamed
158
- * @param name new name to be assigned to the file
161
+ * @param oldPath id of the file to be renamed
162
+ * @param newPath new name to be assigned to the file
159
163
  */
160
- renameFile(hash: string, id: number, name: string): Promise<boolean>;
164
+ renameFile(hash: string, oldPath: string, newPath: string): Promise<boolean>;
161
165
  /**
162
166
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
163
167
  */
@@ -206,5 +210,5 @@ export declare class QBittorrent implements TorrentClient {
206
210
  */
207
211
  login(): Promise<boolean>;
208
212
  logout(): boolean;
209
- request<T>(path: string, method: 'GET' | 'POST', params?: Record<string, string | number>, body?: URLSearchParams | FormData, headers?: any, json?: boolean): Promise<T>;
213
+ request<T>(path: string, method: 'GET' | 'POST', params?: Record<string, string | number>, body?: URLSearchParams | FormData, headers?: Record<string, string>, isJson?: boolean): Promise<T>;
210
214
  }
@@ -44,6 +44,13 @@ export class QBittorrent {
44
44
  const res = await this.request('/app/webapiVersion', 'GET', undefined, undefined, undefined, false);
45
45
  return res;
46
46
  }
47
+ /**
48
+ * Get default save path
49
+ */
50
+ async getDefaultSavePath() {
51
+ const res = await this.request('/app/defaultSavePath', 'GET', undefined, undefined, undefined, false);
52
+ return res;
53
+ }
47
54
  /**
48
55
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-build-info}
49
56
  */
@@ -161,12 +168,12 @@ export class QBittorrent {
161
168
  return res;
162
169
  }
163
170
  async setFilePriority(hash, fileIds, priority) {
164
- const res = await this.request('/torrents/filePrio', 'GET', {
171
+ await this.request('/torrents/filePrio', 'POST', undefined, objToUrlSearchParams({
165
172
  hash,
166
173
  id: normalizeHashes(fileIds),
167
- priority,
168
- });
169
- return res;
174
+ priority: priority.toString(),
175
+ }), undefined, false);
176
+ return true;
170
177
  }
171
178
  /**
172
179
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-states}
@@ -320,7 +327,7 @@ export class QBittorrent {
320
327
  hashes: normalizeHashes(hashes),
321
328
  deleteFiles,
322
329
  };
323
- await this.request('/torrents/delete', 'POST', undefined, objToUrlSearchParams(data));
330
+ await this.request('/torrents/delete', 'POST', undefined, objToUrlSearchParams(data), undefined, false);
324
331
  return true;
325
332
  }
326
333
  /**
@@ -398,26 +405,26 @@ export class QBittorrent {
398
405
  }
399
406
  /**
400
407
  * @param hash Hash for desired torrent
401
- * @param id id of the file to be renamed
402
- * @param name new name to be assigned to the file
408
+ * @param oldPath id of the file to be renamed
409
+ * @param newPath new name to be assigned to the file
403
410
  */
404
- async renameFile(hash, id, name) {
405
- const form = new FormData();
406
- form.append('hash', hash);
407
- form.append('id', id.toString());
408
- form.append('name', name);
409
- await this.request('/torrents/renameFile', 'POST', undefined, undefined, form, false);
411
+ async renameFile(hash, oldPath, newPath) {
412
+ await this.request('/torrents/renameFile', 'POST', undefined, objToUrlSearchParams({
413
+ hash,
414
+ oldPath,
415
+ newPath,
416
+ }), undefined, false);
410
417
  return true;
411
418
  }
412
419
  /**
413
420
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
414
421
  */
415
422
  async renameFolder(hash, oldPath, newPath) {
416
- const form = new FormData();
417
- form.append('hash', hash);
418
- form.append('oldPath', oldPath);
419
- form.append('newPath', newPath);
420
- await this.request('/torrents/renameFolder', 'POST', undefined, undefined, form, false);
423
+ await this.request('/torrents/renameFolder', 'POST', undefined, objToUrlSearchParams({
424
+ hash,
425
+ oldPath,
426
+ newPath,
427
+ }), undefined, false);
421
428
  return true;
422
429
  }
423
430
  /**
@@ -559,7 +566,7 @@ export class QBittorrent {
559
566
  return true;
560
567
  }
561
568
  // eslint-disable-next-line max-params
562
- async request(path, method, params, body, headers = {}, json = true) {
569
+ async request(path, method, params, body, headers = {}, isJson = true) {
563
570
  if (!this._sid || !this._exp || this._exp.getTime() < new Date().getTime()) {
564
571
  const authed = await this.login();
565
572
  if (!authed) {
@@ -575,10 +582,11 @@ export class QBittorrent {
575
582
  },
576
583
  body,
577
584
  params,
578
- // allow proxy agent
579
585
  retry: 0,
580
586
  timeout: this.config.timeout,
581
- responseType: json ? 'json' : 'text',
587
+ // casting to json to avoid type error
588
+ responseType: isJson ? 'json' : 'text',
589
+ // allow proxy agent
582
590
  // @ts-expect-error for some reason agent is not in the type
583
591
  agent: this.config.agent,
584
592
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/qbittorrent",
3
- "version": "8.1.0",
3
+ "version": "8.3.0",
4
4
  "description": "TypeScript api wrapper for qbittorrent using got",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "license": "MIT",
@@ -42,21 +42,21 @@
42
42
  "cookie": "^0.6.0",
43
43
  "node-fetch-native": "^1.6.4",
44
44
  "ofetch": "^1.3.4",
45
- "ufo": "^1.5.3",
46
- "uint8array-extras": "^1.2.0"
45
+ "ufo": "^1.5.4",
46
+ "uint8array-extras": "^1.4.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@biomejs/biome": "1.8.3",
50
- "@ctrl/eslint-config-biome": "3.1.0",
51
- "@eslint/compat": "^1.1.0",
50
+ "@ctrl/eslint-config-biome": "4.1.4",
51
+ "@eslint/compat": "^1.1.1",
52
52
  "@sindresorhus/tsconfig": "6.0.0",
53
53
  "@types/cookie": "0.6.0",
54
- "@types/node": "20.14.9",
55
- "@vitest/coverage-v8": "1.6.0",
54
+ "@types/node": "22.5.0",
55
+ "@vitest/coverage-v8": "2.0.5",
56
56
  "p-wait-for": "5.0.2",
57
- "typedoc": "0.26.3",
58
- "typescript": "5.5.3",
59
- "vitest": "1.6.0"
57
+ "typedoc": "0.26.6",
58
+ "typescript": "5.5.4",
59
+ "vitest": "2.0.5"
60
60
  },
61
61
  "release": {
62
62
  "branches": [