@ctrl/deluge 5.0.1 → 6.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.
@@ -1,5 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { FetchResponse } from 'ofetch';
1
+ import { ofetch } from 'ofetch';
3
2
  import type { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentSettings } from '@ctrl/shared-torrent';
4
3
  import type { AddTorrentOptions, AddTorrentResponse, BooleanStatus, ConfigResponse, DefaultResponse, DelugeSettings, GetHostsResponse, GetHostStatusResponse, ListMethods, PluginInfo, PluginsListResponse, StringStatus, TorrentFiles, TorrentInfo, TorrentListResponse, TorrentOptions, TorrentStatus, Tracker, UploadResponse } from './types.js';
5
4
  export declare class Deluge implements TorrentClient {
@@ -56,7 +55,7 @@ export declare class Deluge implements TorrentClient {
56
55
  * @returns a list of method names
57
56
  */
58
57
  listMethods(auth?: boolean): Promise<ListMethods>;
59
- upload(torrent: string | Buffer): Promise<UploadResponse>;
58
+ upload(torrent: string | Uint8Array): Promise<UploadResponse>;
60
59
  /**
61
60
  * Download a torrent from url, pass the result to {@link Deluge.addTorrent}
62
61
  * @param url
@@ -64,8 +63,8 @@ export declare class Deluge implements TorrentClient {
64
63
  * @returns file path
65
64
  */
66
65
  downloadFromUrl(url: string, cookies?: string): Promise<string>;
67
- addTorrent(torrent: string | Buffer, config?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
68
- normalizedAddTorrent(torrent: string | Buffer, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
66
+ addTorrent(torrent: string | Uint8Array, config?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
67
+ normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
69
68
  addTorrentMagnet(magnet: string, config?: Partial<AddTorrentOptions>): Promise<BooleanStatus>;
70
69
  /**
71
70
  *
@@ -106,6 +105,6 @@ export declare class Deluge implements TorrentClient {
106
105
  getPluginInfo(plugins: string[]): Promise<PluginInfo>;
107
106
  enablePlugin(plugins: string[]): Promise<DefaultResponse>;
108
107
  disablePlugin(plugins: string[]): Promise<DefaultResponse>;
109
- request<T extends object>(method: string, params?: any[], needsAuth?: boolean, autoConnect?: boolean): Promise<FetchResponse<T>>;
108
+ request<T extends object>(method: string, params?: any[], needsAuth?: boolean, autoConnect?: boolean): Promise<ReturnType<typeof ofetch.raw<T>>>;
110
109
  private _validateAuth;
111
110
  }
@@ -2,6 +2,7 @@ import { FormData } from 'node-fetch-native';
2
2
  import { ofetch } from 'ofetch';
3
3
  import { Cookie } from 'tough-cookie';
4
4
  import { joinURL } from 'ufo';
5
+ import { base64ToUint8Array, isUint8Array, stringToUint8Array } from 'uint8array-extras';
5
6
  import { magnetDecode } from '@ctrl/magnet-link';
6
7
  import { normalizeTorrentData } from './normalizeTorrentData.js';
7
8
  const defaults = {
@@ -153,7 +154,7 @@ export class Deluge {
153
154
  const form = new FormData();
154
155
  const type = { type: 'application/x-bittorrent' };
155
156
  if (typeof torrent === 'string') {
156
- form.set('file', new File([Buffer.from(torrent, 'base64')], 'file.torrent', type));
157
+ form.set('file', new File([base64ToUint8Array(torrent)], 'file.torrent', type));
157
158
  }
158
159
  else {
159
160
  const file = new File([torrent], 'torrent', type);
@@ -187,7 +188,7 @@ export class Deluge {
187
188
  }
188
189
  async addTorrent(torrent, config = {}) {
189
190
  let path;
190
- if (Buffer.isBuffer(torrent) || !torrent.startsWith('/tmp/')) {
191
+ if (isUint8Array(torrent) || !torrent.startsWith('/tmp/')) {
191
192
  const upload = await this.upload(torrent);
192
193
  if (!upload.success || !upload.files.length) {
193
194
  throw new Error('Failed to upload');
@@ -238,8 +239,8 @@ export class Deluge {
238
239
  await this.addTorrentMagnet(torrent, torrentOptions);
239
240
  }
240
241
  else {
241
- if (!Buffer.isBuffer(torrent)) {
242
- torrent = Buffer.from(torrent);
242
+ if (!isUint8Array(torrent)) {
243
+ torrent = stringToUint8Array(torrent);
243
244
  }
244
245
  const res = await this.addTorrent(torrent, torrentOptions);
245
246
  torrentHash = res.result[0][1];
@@ -548,9 +549,7 @@ export class Deluge {
548
549
  }
549
550
  async _validateAuth() {
550
551
  let validAuth = await this.checkSession();
551
- if (!validAuth) {
552
- validAuth = await this.login();
553
- }
552
+ validAuth ||= await this.login();
554
553
  if (!validAuth) {
555
554
  throw new Error('Invalid Auth');
556
555
  }
@@ -16,7 +16,7 @@ export interface ListMethods extends DefaultResponse {
16
16
  result: string[];
17
17
  }
18
18
  export interface AddTorrentResponse extends DefaultResponse {
19
- result: Array<[boolean, string]>;
19
+ result: [boolean, string][];
20
20
  }
21
21
  /**
22
22
  * ex -
@@ -35,7 +35,7 @@ export interface GetHostsResponse extends DefaultResponse {
35
35
  * port - 58846
36
36
  * status - "Online"
37
37
  */
38
- result: Array<[string, string, number, string]>;
38
+ result: [string, string, number, string][];
39
39
  }
40
40
  export type HostStatus = 'Online' | 'Offline' | 'Connected';
41
41
  export interface GetHostStatusResponse extends DefaultResponse {
@@ -101,9 +101,9 @@ export interface TorrentList {
101
101
  * ['label', 'id']
102
102
  */
103
103
  export interface TorrentFilters {
104
- state: Array<[string, number]>;
105
- tracker_host: Array<[string, number]>;
106
- label?: Array<[string, number]>;
104
+ state: [string, number][];
105
+ tracker_host: [string, number][];
106
+ label?: [string, number][];
107
107
  }
108
108
  export interface Stats {
109
109
  upload_protocol_rate: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/deluge",
3
- "version": "5.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "TypeScript api wrapper for deluge using got",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "license": "MIT",
@@ -18,8 +18,12 @@
18
18
  ],
19
19
  "sideEffects": false,
20
20
  "scripts": {
21
- "lint": "eslint --ext .js,.ts, .",
22
- "lint:fix": "eslint --fix --ext .js,.ts, .",
21
+ "lint": "pnpm run '/^(lint:biome|lint:eslint)$/'",
22
+ "lint:biome": "biome check .",
23
+ "lint:eslint": "eslint .",
24
+ "lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
25
+ "lint:eslint:fix": "eslint . --fix",
26
+ "lint:biome:fix": "biome check . --apply",
23
27
  "prepare": "npm run build",
24
28
  "build": "tsc",
25
29
  "build:docs": "typedoc",
@@ -28,23 +32,25 @@
28
32
  "test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
29
33
  },
30
34
  "dependencies": {
31
- "@ctrl/magnet-link": "^3.1.2",
32
- "@ctrl/shared-torrent": "^5.0.0",
33
- "node-fetch-native": "^1.4.1",
34
- "ofetch": "^1.3.3",
35
- "tough-cookie": "^4.1.3",
36
- "ufo": "^1.3.1"
35
+ "@ctrl/magnet-link": "^4.0.2",
36
+ "@ctrl/shared-torrent": "^6.0.0",
37
+ "node-fetch-native": "^1.6.4",
38
+ "ofetch": "^1.3.4",
39
+ "tough-cookie": "^4.1.4",
40
+ "ufo": "^1.5.3",
41
+ "uint8array-extras": "^1.2.0"
37
42
  },
38
43
  "devDependencies": {
39
- "@ctrl/eslint-config": "4.0.9",
40
- "@sindresorhus/tsconfig": "5.0.0",
41
- "@types/node": "20.8.10",
42
- "@types/tough-cookie": "4.0.4",
43
- "@vitest/coverage-v8": "0.34.6",
44
+ "@biomejs/biome": "1.8.3",
45
+ "@ctrl/eslint-config-biome": "3.1.3",
46
+ "@sindresorhus/tsconfig": "6.0.0",
47
+ "@types/node": "20.14.9",
48
+ "@types/tough-cookie": "4.0.5",
49
+ "@vitest/coverage-v8": "1.6.0",
44
50
  "p-wait-for": "5.0.2",
45
- "typedoc": "0.25.3",
46
- "typescript": "5.2.2",
47
- "vitest": "0.34.6"
51
+ "typedoc": "0.26.3",
52
+ "typescript": "5.5.3",
53
+ "vitest": "1.6.0"
48
54
  },
49
55
  "publishConfig": {
50
56
  "access": "public",