@ctrl/deluge 5.0.1 → 6.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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { FetchResponse } 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';
@@ -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
  *
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/deluge",
3
- "version": "5.0.1",
3
+ "version": "6.0.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 --ext .ts,.tsx .",
24
+ "lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
25
+ "lint:eslint:fix": "eslint --ext .ts,.tsx . --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",
35
+ "@ctrl/magnet-link": "^4.0.1",
36
+ "@ctrl/shared-torrent": "^6.0.0",
37
+ "node-fetch-native": "^1.6.2",
34
38
  "ofetch": "^1.3.3",
35
39
  "tough-cookie": "^4.1.3",
36
- "ufo": "^1.3.1"
40
+ "ufo": "^1.4.0",
41
+ "uint8array-extras": "^1.1.0"
37
42
  },
38
43
  "devDependencies": {
39
- "@ctrl/eslint-config": "4.0.9",
44
+ "@biomejs/biome": "1.5.3",
45
+ "@ctrl/eslint-config-biome": "2.0.9",
40
46
  "@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",
47
+ "@types/node": "20.11.24",
48
+ "@types/tough-cookie": "4.0.5",
49
+ "@vitest/coverage-v8": "1.3.1",
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.25.10",
52
+ "typescript": "5.3.3",
53
+ "vitest": "1.3.1"
48
54
  },
49
55
  "publishConfig": {
50
56
  "access": "public",