@ctrl/qbittorrent 8.2.0 → 9.0.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.
@@ -68,7 +68,7 @@ export declare class QBittorrent implements TorrentClient {
68
68
  */
69
69
  torrentWebSeeds(hash: string): Promise<WebSeed[]>;
70
70
  torrentFiles(hash: string): Promise<TorrentFile[]>;
71
- setFilePriority(hash: string, fileIds: string | string[], priority: TorrentFilePriority): Promise<TorrentFile[]>;
71
+ setFilePriority(hash: string, fileIds: string | string[], priority: TorrentFilePriority): Promise<boolean>;
72
72
  /**
73
73
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-states}
74
74
  */
@@ -144,6 +144,7 @@ export declare class QBittorrent implements TorrentClient {
144
144
  resumeTorrent(hashes: string | string[] | 'all'): Promise<boolean>;
145
145
  /**
146
146
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#delete-torrents}
147
+ * @param deleteFiles (default: false) remove files from disk
147
148
  */
148
149
  removeTorrent(hashes: string | string[] | 'all', deleteFiles?: boolean): Promise<boolean>;
149
150
  /**
@@ -158,10 +159,10 @@ export declare class QBittorrent implements TorrentClient {
158
159
  normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
159
160
  /**
160
161
  * @param hash Hash for desired torrent
161
- * @param id id of the file to be renamed
162
- * @param name new name to be assigned to the file
162
+ * @param oldPath id of the file to be renamed
163
+ * @param newPath new name to be assigned to the file
163
164
  */
164
- renameFile(hash: string, id: number, name: string): Promise<boolean>;
165
+ renameFile(hash: string, oldPath: string, newPath: string): Promise<boolean>;
165
166
  /**
166
167
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
167
168
  */
@@ -210,5 +211,5 @@ export declare class QBittorrent implements TorrentClient {
210
211
  */
211
212
  login(): Promise<boolean>;
212
213
  logout(): boolean;
213
- request<T>(path: string, method: 'GET' | 'POST', params?: Record<string, string | number>, body?: URLSearchParams | FormData, headers?: any, json?: boolean): Promise<T>;
214
+ request<T>(path: string, method: 'GET' | 'POST', params?: Record<string, string | number>, body?: URLSearchParams | FormData, headers?: Record<string, string>, isJson?: boolean): Promise<T>;
214
215
  }
@@ -168,12 +168,12 @@ export class QBittorrent {
168
168
  return res;
169
169
  }
170
170
  async setFilePriority(hash, fileIds, priority) {
171
- const res = await this.request('/torrents/filePrio', 'GET', {
171
+ await this.request('/torrents/filePrio', 'POST', undefined, objToUrlSearchParams({
172
172
  hash,
173
173
  id: normalizeHashes(fileIds),
174
- priority,
175
- });
176
- return res;
174
+ priority: priority.toString(),
175
+ }), undefined, false);
176
+ return true;
177
177
  }
178
178
  /**
179
179
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-states}
@@ -321,13 +321,14 @@ export class QBittorrent {
321
321
  }
322
322
  /**
323
323
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#delete-torrents}
324
+ * @param deleteFiles (default: false) remove files from disk
324
325
  */
325
- async removeTorrent(hashes, deleteFiles = true) {
326
+ async removeTorrent(hashes, deleteFiles = false) {
326
327
  const data = {
327
328
  hashes: normalizeHashes(hashes),
328
329
  deleteFiles,
329
330
  };
330
- await this.request('/torrents/delete', 'POST', undefined, objToUrlSearchParams(data));
331
+ await this.request('/torrents/delete', 'POST', undefined, objToUrlSearchParams(data), undefined, false);
331
332
  return true;
332
333
  }
333
334
  /**
@@ -405,26 +406,26 @@ export class QBittorrent {
405
406
  }
406
407
  /**
407
408
  * @param hash Hash for desired torrent
408
- * @param id id of the file to be renamed
409
- * @param name new name to be assigned to the file
409
+ * @param oldPath id of the file to be renamed
410
+ * @param newPath new name to be assigned to the file
410
411
  */
411
- async renameFile(hash, id, name) {
412
- const form = new FormData();
413
- form.append('hash', hash);
414
- form.append('id', id.toString());
415
- form.append('name', name);
416
- await this.request('/torrents/renameFile', 'POST', undefined, undefined, form, false);
412
+ async renameFile(hash, oldPath, newPath) {
413
+ await this.request('/torrents/renameFile', 'POST', undefined, objToUrlSearchParams({
414
+ hash,
415
+ oldPath,
416
+ newPath,
417
+ }), undefined, false);
417
418
  return true;
418
419
  }
419
420
  /**
420
421
  * {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
421
422
  */
422
423
  async renameFolder(hash, oldPath, newPath) {
423
- const form = new FormData();
424
- form.append('hash', hash);
425
- form.append('oldPath', oldPath);
426
- form.append('newPath', newPath);
427
- await this.request('/torrents/renameFolder', 'POST', undefined, undefined, form, false);
424
+ await this.request('/torrents/renameFolder', 'POST', undefined, objToUrlSearchParams({
425
+ hash,
426
+ oldPath,
427
+ newPath,
428
+ }), undefined, false);
428
429
  return true;
429
430
  }
430
431
  /**
@@ -566,7 +567,7 @@ export class QBittorrent {
566
567
  return true;
567
568
  }
568
569
  // eslint-disable-next-line max-params
569
- async request(path, method, params, body, headers = {}, json = true) {
570
+ async request(path, method, params, body, headers = {}, isJson = true) {
570
571
  if (!this._sid || !this._exp || this._exp.getTime() < new Date().getTime()) {
571
572
  const authed = await this.login();
572
573
  if (!authed) {
@@ -582,10 +583,11 @@ export class QBittorrent {
582
583
  },
583
584
  body,
584
585
  params,
585
- // allow proxy agent
586
586
  retry: 0,
587
587
  timeout: this.config.timeout,
588
- responseType: json ? 'json' : 'text',
588
+ // casting to json to avoid type error
589
+ responseType: isJson ? 'json' : 'text',
590
+ // allow proxy agent
589
591
  // @ts-expect-error for some reason agent is not in the type
590
592
  agent: this.config.agent,
591
593
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/qbittorrent",
3
- "version": "8.2.0",
3
+ "version": "9.0.0",
4
4
  "description": "TypeScript api wrapper for qbittorrent using got",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "license": "MIT",
@@ -47,16 +47,16 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@biomejs/biome": "1.8.3",
50
- "@ctrl/eslint-config-biome": "3.1.3",
50
+ "@ctrl/eslint-config-biome": "4.1.4",
51
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.11",
55
- "@vitest/coverage-v8": "2.0.3",
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.4",
58
- "typescript": "5.5.3",
59
- "vitest": "2.0.3"
57
+ "typedoc": "0.26.6",
58
+ "typescript": "5.5.4",
59
+ "vitest": "2.0.5"
60
60
  },
61
61
  "release": {
62
62
  "branches": [