cross-seed 5.9.2 → 6.0.0-1

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.
Files changed (63) hide show
  1. package/README.md +7 -1
  2. package/dist/Result.js +2 -0
  3. package/dist/Result.js.map +1 -1
  4. package/dist/action.js +127 -62
  5. package/dist/action.js.map +1 -1
  6. package/dist/auth.js +5 -5
  7. package/dist/auth.js.map +1 -1
  8. package/dist/clients/Deluge.js +104 -51
  9. package/dist/clients/Deluge.js.map +1 -1
  10. package/dist/clients/QBittorrent.js +205 -122
  11. package/dist/clients/QBittorrent.js.map +1 -1
  12. package/dist/clients/RTorrent.js +57 -23
  13. package/dist/clients/RTorrent.js.map +1 -1
  14. package/dist/clients/TorrentClient.js.map +1 -1
  15. package/dist/clients/Transmission.js +17 -9
  16. package/dist/clients/Transmission.js.map +1 -1
  17. package/dist/cmd.js +89 -77
  18. package/dist/cmd.js.map +1 -1
  19. package/dist/config.template.cjs +237 -144
  20. package/dist/config.template.cjs.map +1 -1
  21. package/dist/configSchema.js +177 -0
  22. package/dist/configSchema.js.map +1 -0
  23. package/dist/configuration.js +35 -9
  24. package/dist/configuration.js.map +1 -1
  25. package/dist/constants.js +28 -12
  26. package/dist/constants.js.map +1 -1
  27. package/dist/dataFiles.js +17 -8
  28. package/dist/dataFiles.js.map +1 -1
  29. package/dist/decide.js +118 -28
  30. package/dist/decide.js.map +1 -1
  31. package/dist/diff.js.map +1 -1
  32. package/dist/errors.js.map +1 -1
  33. package/dist/indexers.js +3 -3
  34. package/dist/indexers.js.map +1 -1
  35. package/dist/jobs.js +15 -7
  36. package/dist/jobs.js.map +1 -1
  37. package/dist/logger.js +9 -9
  38. package/dist/logger.js.map +1 -1
  39. package/dist/migrations/00-initialSchema.js.map +1 -1
  40. package/dist/migrations/02-timestamps.js +3 -1
  41. package/dist/migrations/02-timestamps.js.map +1 -1
  42. package/dist/parseTorrent.js +11 -2
  43. package/dist/parseTorrent.js.map +1 -1
  44. package/dist/pipeline.js +34 -25
  45. package/dist/pipeline.js.map +1 -1
  46. package/dist/preFilter.js +17 -6
  47. package/dist/preFilter.js.map +1 -1
  48. package/dist/pushNotifier.js +29 -10
  49. package/dist/pushNotifier.js.map +1 -1
  50. package/dist/searchee.js +8 -1
  51. package/dist/searchee.js.map +1 -1
  52. package/dist/server.js.map +1 -1
  53. package/dist/startup.js +62 -23
  54. package/dist/startup.js.map +1 -1
  55. package/dist/torrent.js +14 -29
  56. package/dist/torrent.js.map +1 -1
  57. package/dist/torznab.js +56 -32
  58. package/dist/torznab.js.map +1 -1
  59. package/dist/utils.js +42 -5
  60. package/dist/utils.js.map +1 -1
  61. package/package.json +12 -12
  62. package/dist/config.template.docker.cjs +0 -236
  63. package/dist/config.template.docker.cjs.map +0 -1
package/README.md CHANGED
@@ -17,9 +17,15 @@ files to a folder you specify. After that, I recommend using
17
17
  [AutoTorrent2](https://github.com/JohnDoee/autotorrent2) to do the last-mile
18
18
  delivery into your client.
19
19
 
20
+ ## 🚨🚨🚨 Breaking changes in cross-seed v6 🚨🚨🚨
21
+
22
+ Head on over to the
23
+ [v6 migration guide](https://www.cross-seed.org/docs/v6-migration)
24
+ to see the steps required for migration.
25
+
20
26
  ## Requirements
21
27
 
22
- - [Node 16+](https://nodejs.org/en/download)
28
+ - [Node >= 20](https://nodejs.org/en/download)
23
29
  - Any number of indexers that support Torznab (use Jackett or Prowlarr to
24
30
  help)
25
31
 
package/dist/Result.js CHANGED
@@ -1,4 +1,5 @@
1
1
  class OkResult {
2
+ contents;
2
3
  constructor(contents) {
3
4
  this.contents = contents;
4
5
  }
@@ -24,6 +25,7 @@ class OkResult {
24
25
  }
25
26
  }
26
27
  class ErrResult {
28
+ contents;
27
29
  constructor(contents) {
28
30
  this.contents = contents;
29
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Result.js","sourceRoot":"","sources":["../src/Result.ts"],"names":[],"mappings":"AASA,MAAM,QAAQ;IAGb,YAAY,QAAW;QACtB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UAAU,QAAQ,CAAO,KAAQ;IACtC,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAO,KAAQ;IACzC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC"}
package/dist/action.js CHANGED
@@ -1,67 +1,147 @@
1
1
  import chalk from "chalk";
2
- import { existsSync, linkSync, mkdirSync, readdirSync, statSync, symlinkSync, } from "fs";
3
- import { join, resolve, dirname, basename } from "path";
2
+ import { existsSync, linkSync, mkdirSync, statSync, symlinkSync } from "fs";
3
+ import { dirname, join, resolve } from "path";
4
4
  import { getClient } from "./clients/TorrentClient.js";
5
5
  import { Action, Decision, InjectionResult, LinkType, SaveResult, } from "./constants.js";
6
6
  import { logger } from "./logger.js";
7
+ import { resultOf, resultOfErr } from "./Result.js";
7
8
  import { getRuntimeConfig } from "./runtimeConfig.js";
9
+ import { hasVideo } from "./searchee.js";
8
10
  import { saveTorrentFile } from "./torrent.js";
9
11
  import { getTag } from "./utils.js";
10
- import { CrossSeedError } from "./errors.js";
11
- export async function validateAction() {
12
- const { action } = getRuntimeConfig();
13
- if (action !== Action.INJECT && action !== Action.SAVE) {
14
- throw new CrossSeedError(`Action method "${action}" is invalid. Allowed choices are "save" and "inject".`);
12
+ function logInjectionResult(result, tracker, name, decision) {
13
+ const styledName = chalk.green.bold(name);
14
+ const styledTracker = chalk.bold(tracker);
15
+ switch (result) {
16
+ case InjectionResult.SUCCESS:
17
+ logger.info(`Found ${styledName} on ${styledTracker} by ${decision} - injected`);
18
+ break;
19
+ case InjectionResult.ALREADY_EXISTS:
20
+ logger.info(`Found ${styledName} on ${styledTracker} by ${decision} - exists`);
21
+ break;
22
+ case InjectionResult.TORRENT_NOT_COMPLETE:
23
+ logger.warn(`Found ${styledName} on ${styledTracker} by ${decision} - skipping incomplete torrent`);
24
+ break;
25
+ case InjectionResult.FAILURE:
26
+ default:
27
+ logger.error(`Found ${styledName} on ${styledTracker} by ${decision} - failed to inject, saving instead`);
28
+ break;
15
29
  }
16
30
  }
17
- export async function performAction(newMeta, decision, searchee, tracker) {
18
- const { action, linkDir } = getRuntimeConfig();
19
- if (searchee.path) {
20
- if (decision == Decision.MATCH) {
21
- await linkExact(searchee.path, linkDir);
31
+ /**
32
+ * @return the root of linked files.
33
+ */
34
+ function linkExactTree(newMeta, destinationDir, sourceRoot) {
35
+ if (newMeta.files.length === 1) {
36
+ return fuzzyLinkOneFile(newMeta, destinationDir, sourceRoot);
37
+ }
38
+ for (const newFile of newMeta.files) {
39
+ const srcFilePath = join(dirname(sourceRoot), newFile.path);
40
+ const destFilePath = join(destinationDir, newFile.path);
41
+ mkdirSync(dirname(destFilePath), { recursive: true });
42
+ linkFile(srcFilePath, destFilePath);
43
+ }
44
+ return join(destinationDir, newMeta.name);
45
+ }
46
+ /**
47
+ * @return the root of linked file.
48
+ */
49
+ function fuzzyLinkOneFile(newMeta, destinationDir, sourceRoot) {
50
+ const srcFilePath = sourceRoot;
51
+ const destFilePath = join(destinationDir, newMeta.files[0].path);
52
+ mkdirSync(dirname(destFilePath), { recursive: true });
53
+ linkFile(srcFilePath, destFilePath);
54
+ return join(destinationDir, newMeta.name);
55
+ }
56
+ /**
57
+ * @return the root of linked files.
58
+ */
59
+ function fuzzyLinkPartial(searchee, newMeta, destinationDir, sourceRoot) {
60
+ for (const newFile of newMeta.files) {
61
+ let matchedSearcheeFiles = searchee.files.filter((searcheeFile) => searcheeFile.length === newFile.length);
62
+ if (matchedSearcheeFiles.length > 1) {
63
+ matchedSearcheeFiles = matchedSearcheeFiles.filter((searcheeFile) => searcheeFile.name === newFile.name);
22
64
  }
23
- else if (decision == Decision.MATCH_SIZE_ONLY) {
24
- // Size only matching is only supported for single file or
25
- // single, nested file torrents.
26
- const candidateParentDir = dirname(newMeta.files[0].path);
27
- let correctedlinkDir = linkDir;
28
- // Candidate is single, nested file
29
- if (candidateParentDir !== ".") {
30
- mkdirSync(join(linkDir, candidateParentDir), {
31
- recursive: true,
32
- });
33
- correctedlinkDir = join(linkDir, candidateParentDir);
34
- }
35
- linkFile(searchee.path, join(correctedlinkDir, newMeta.files[0].name));
65
+ if (matchedSearcheeFiles.length) {
66
+ const srcFilePath = statSync(sourceRoot).isFile()
67
+ ? sourceRoot
68
+ : join(dirname(sourceRoot), matchedSearcheeFiles[0].path);
69
+ const destFilePath = join(destinationDir, newFile.path);
70
+ mkdirSync(dirname(destFilePath), { recursive: true });
71
+ linkFile(srcFilePath, destFilePath);
36
72
  }
37
73
  }
38
- const styledName = chalk.green.bold(newMeta.name);
39
- const styledTracker = chalk.bold(tracker);
40
- if (action === Action.INJECT) {
41
- const result = await getClient().inject(newMeta, searchee, searchee.path ? linkDir : undefined);
42
- switch (result) {
43
- case InjectionResult.SUCCESS:
44
- logger.info(`Found ${styledName} on ${styledTracker} - injected`);
45
- break;
46
- case InjectionResult.ALREADY_EXISTS:
47
- logger.info(`Found ${styledName} on ${styledTracker} - exists`);
48
- break;
49
- case InjectionResult.TORRENT_NOT_COMPLETE:
50
- logger.warn(`Found ${styledName} on ${styledTracker} - skipping incomplete torrent`);
51
- break;
52
- case InjectionResult.FAILURE:
53
- default:
54
- logger.error(`Found ${styledName} on ${styledTracker} - failed to inject, saving instead`);
55
- saveTorrentFile(tracker, getTag(searchee.name), newMeta);
56
- break;
74
+ return join(destinationDir, newMeta.name);
75
+ }
76
+ async function linkAllFilesInMetafile(searchee, newMeta, tracker, decision) {
77
+ const { linkDir, flatLinking } = getRuntimeConfig();
78
+ const fullLinkDir = flatLinking ? linkDir : join(linkDir, tracker);
79
+ let sourceRoot;
80
+ if (searchee.path) {
81
+ sourceRoot = searchee.path;
82
+ }
83
+ else {
84
+ const downloadDirResult = await getClient().getDownloadDir(searchee);
85
+ if (downloadDirResult.isErr()) {
86
+ return downloadDirResult.mapErr((e) => e === "NOT_FOUND" ? "TORRENT_NOT_FOUND" : e);
57
87
  }
58
- return result;
88
+ sourceRoot = join(downloadDirResult.unwrapOrThrow(), searchee.files.length === 1
89
+ ? searchee.files[0].path
90
+ : searchee.name);
91
+ }
92
+ if (!existsSync(sourceRoot)) {
93
+ logger.error(`Linking failed, ${sourceRoot} not found. Make sure Docker volume mounts are set up properly.`);
94
+ return resultOfErr("MISSING_DATA");
95
+ }
96
+ if (decision === Decision.MATCH) {
97
+ return resultOf(linkExactTree(newMeta, fullLinkDir, sourceRoot));
98
+ }
99
+ else if (decision === Decision.MATCH_SIZE_ONLY) {
100
+ return resultOf(fuzzyLinkOneFile(newMeta, fullLinkDir, sourceRoot));
59
101
  }
60
102
  else {
61
- saveTorrentFile(tracker, getTag(searchee.name), newMeta);
62
- logger.info(`Found ${styledName} on ${styledTracker} - saved`);
103
+ return resultOf(fuzzyLinkPartial(searchee, newMeta, fullLinkDir, sourceRoot));
104
+ }
105
+ }
106
+ export async function performAction(newMeta, decision, searchee, tracker) {
107
+ const { action, linkDir } = getRuntimeConfig();
108
+ const isVideo = hasVideo(searchee);
109
+ if (action === Action.SAVE) {
110
+ await saveTorrentFile(tracker, getTag(searchee.name, isVideo), newMeta);
111
+ const styledName = chalk.green.bold(newMeta.name);
112
+ const styledTracker = chalk.bold(tracker);
113
+ logger.info(`Found ${styledName} on ${styledTracker} by ${decision} - saved`);
63
114
  return SaveResult.SAVED;
64
115
  }
116
+ let destinationDir;
117
+ if (linkDir) {
118
+ const linkedFilesRootResult = await linkAllFilesInMetafile(searchee, newMeta, tracker, decision);
119
+ if (linkedFilesRootResult.isOk()) {
120
+ destinationDir = dirname(linkedFilesRootResult.unwrapOrThrow());
121
+ }
122
+ else if (decision === Decision.MATCH &&
123
+ linkedFilesRootResult.unwrapErrOrThrow() === "MISSING_DATA") {
124
+ logger.warn("Falling back to non-linking.");
125
+ if (searchee.path) {
126
+ destinationDir = dirname(searchee.path);
127
+ }
128
+ }
129
+ else {
130
+ logInjectionResult(InjectionResult.FAILURE, tracker, newMeta.name, decision);
131
+ await saveTorrentFile(tracker, getTag(searchee.name, isVideo), newMeta);
132
+ return InjectionResult.FAILURE;
133
+ }
134
+ }
135
+ else if (searchee.path) {
136
+ // should be a MATCH, as risky requires a linkDir to be set
137
+ destinationDir = dirname(searchee.path);
138
+ }
139
+ const result = await getClient().inject(newMeta, searchee, decision, destinationDir);
140
+ logInjectionResult(result, tracker, newMeta.name, decision);
141
+ if (result === InjectionResult.FAILURE) {
142
+ await saveTorrentFile(tracker, getTag(searchee.name, isVideo), newMeta);
143
+ }
144
+ return result;
65
145
  }
66
146
  export async function performActions(searchee, matches) {
67
147
  const results = [];
@@ -73,21 +153,6 @@ export async function performActions(searchee, matches) {
73
153
  }
74
154
  return results;
75
155
  }
76
- function linkExact(oldPath, newPath) {
77
- if (!newPath) {
78
- return;
79
- }
80
- if (statSync(oldPath).isFile()) {
81
- if (!existsSync(join(newPath, basename(oldPath)))) {
82
- linkFile(oldPath, join(newPath, basename(oldPath)));
83
- }
84
- return;
85
- }
86
- mkdirSync(join(newPath, basename(oldPath)), { recursive: true });
87
- readdirSync(oldPath).forEach((file) => {
88
- linkExact(join(oldPath, file), join(newPath, basename(oldPath)));
89
- });
90
- }
91
156
  function linkFile(oldPath, newPath) {
92
157
  const { linkType } = getRuntimeConfig();
93
158
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACN,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,EACX,QAAQ,EACR,WAAW,GACX,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EACN,MAAM,EAEN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,UAAU,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE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O,CAAC,EAAE,CAAC;QACZ,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO;QAChC,MAAM,CAAC,CAAC;IACT,CAAC;AACF,CAAC"}
package/dist/auth.js CHANGED
@@ -9,17 +9,17 @@ export async function resetApiKey() {
9
9
  await db("settings").update({ apikey });
10
10
  return apikey;
11
11
  }
12
- export async function getApiKeyFromDatabase() {
12
+ export async function getApiKey() {
13
+ const { apiKey: runtimeConfigApiKey } = getRuntimeConfig();
14
+ if (runtimeConfigApiKey)
15
+ return runtimeConfigApiKey;
13
16
  const { apikey } = await db("settings").select("apikey").first();
14
17
  if (!apikey)
15
18
  return resetApiKey();
16
19
  return apikey;
17
20
  }
18
21
  export async function checkApiKey(keyToCheck) {
19
- const { apiAuth } = getRuntimeConfig();
20
- if (!apiAuth)
21
- return true;
22
- const apikey = await getApiKeyFromDatabase();
22
+ const apikey = await getApiKey();
23
23
  return apikey === keyToCheck;
24
24
  }
25
25
  //# sourceMappingURL=auth.js.map
package/dist/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,SAAS,cAAc;IACtB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW;IAChC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB;IAC1C,MAAM,EAAE,MA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AE,CAAC;IACjE,IAAI,CAAC,MAAM;QAAE,OAAO,WAAW,EAAE,CAAC;IAClC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,UAAkB;IACnD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IACjC,OAAO,MAAM,KAAK,UAAU,CAAC;AAC9B,CAAC"}
@@ -1,9 +1,10 @@
1
- import { InjectionResult } from "../constants.js";
1
+ import { InjectionResult, TORRENT_TAG, TORRENT_CATEGORY_SUFFIX, } from "../constants.js";
2
2
  import { CrossSeedError } from "../errors.js";
3
3
  import { Label, logger } from "../logger.js";
4
4
  import { getRuntimeConfig } from "../runtimeConfig.js";
5
- import { extractCredentialsFromUrl } from "../utils.js";
6
- import fetch, { Headers } from "node-fetch";
5
+ import { shouldRecheck, extractCredentialsFromUrl, wait } from "../utils.js";
6
+ import { resultOf, resultOfErr } from "../Result.js";
7
+ import ms from "ms";
7
8
  var DelugeErrorCode;
8
9
  (function (DelugeErrorCode) {
9
10
  DelugeErrorCode[DelugeErrorCode["NO_AUTH"] = 1] = "NO_AUTH";
@@ -13,10 +14,11 @@ var DelugeErrorCode;
13
14
  DelugeErrorCode[DelugeErrorCode["BAD_JSON"] = 5] = "BAD_JSON";
14
15
  })(DelugeErrorCode || (DelugeErrorCode = {}));
15
16
  export default class Deluge {
16
- constructor() {
17
- this.delugeCookie = null;
18
- this.delugeLabel = "cross-seed";
19
- }
17
+ delugeCookie = null;
18
+ delugeLabel = TORRENT_TAG;
19
+ delugeLabelSuffix = TORRENT_CATEGORY_SUFFIX;
20
+ isLabelEnabled;
21
+ delugeRequestId = 0;
20
22
  /**
21
23
  * validates the login and host for deluge webui
22
24
  */
@@ -65,26 +67,30 @@ export default class Deluge {
65
67
  if (this.delugeCookie)
66
68
  headers.set("Cookie", this.delugeCookie);
67
69
  let response, json;
68
- const id = Math.floor(Math.random() * 0x7fffffff);
70
+ const abortController = new AbortController();
71
+ setTimeout(() => void abortController.abort(), ms("10 seconds")).unref();
69
72
  try {
70
73
  response = await fetch(href, {
71
74
  body: JSON.stringify({
72
75
  method,
73
76
  params,
74
- id,
77
+ id: this.delugeRequestId++,
75
78
  }),
76
79
  method: "POST",
77
80
  headers,
81
+ signal: abortController.signal,
78
82
  });
79
83
  }
80
84
  catch (networkError) {
81
- // @ts-expect-error needs es2022 target (tsconfig)
85
+ if (networkError.name === "AbortError") {
86
+ throw new Error(`Deluge method ${method} timed out after 10 seconds`);
87
+ }
82
88
  throw new Error(`Failed to connect to Deluge at ${href}`, {
83
89
  cause: networkError,
84
90
  });
85
91
  }
86
92
  try {
87
- json = await response.json();
93
+ json = (await response.json());
88
94
  }
89
95
  catch (jsonParseError) {
90
96
  throw new Error(`Deluge method ${method} response was non-JSON ${jsonParseError}`);
@@ -96,7 +102,7 @@ export default class Deluge {
96
102
  return this.call(method, params, 0);
97
103
  }
98
104
  else {
99
- throw new Error("Connection lost with Deluge. Reauthentication failed.");
105
+ throw new Error("Connection lost with Deluge. Re-authentication failed.");
100
106
  }
101
107
  }
102
108
  this.handleResponseHeaders(response.headers);
@@ -120,12 +126,32 @@ export default class Deluge {
120
126
  ? false
121
127
  : enabledPlugins.result.includes("Label");
122
128
  }
129
+ // generates the label (string) for injection based on searchee and torrentInfo
130
+ calculateLabel(searchee, torrentInfo) {
131
+ const { linkCategory, duplicateCategories } = getRuntimeConfig();
132
+ if (!searchee.infoHash || !torrentInfo.label) {
133
+ return this.delugeLabel;
134
+ }
135
+ const ogLabel = torrentInfo.label;
136
+ if (!duplicateCategories) {
137
+ return ogLabel;
138
+ }
139
+ const shouldSuffixLabel = !ogLabel.endsWith(this.delugeLabelSuffix) && // no .cross-seed
140
+ ogLabel !== linkCategory; // not data
141
+ return searchee.path
142
+ ? linkCategory
143
+ : shouldSuffixLabel
144
+ ? `${ogLabel}${this.delugeLabelSuffix}`
145
+ : ogLabel;
146
+ }
123
147
  /**
124
148
  * if Label plugin is loaded, adds (if necessary)
125
149
  * and sets the label based on torrent hash.
126
150
  */
127
- async setLabel(infoHash, label) {
128
- if (this.isLabelEnabled) {
151
+ async setLabel(name, infoHash, label) {
152
+ if (!this.isLabelEnabled)
153
+ return;
154
+ try {
129
155
  const setResult = await this.call("label.set_torrent", [
130
156
  infoHash,
131
157
  label,
@@ -135,14 +161,19 @@ export default class Deluge {
135
161
  await this.call("label.set_torrent", [infoHash, label]);
136
162
  }
137
163
  }
164
+ catch (e) {
165
+ logger.warn({
166
+ label: Label.DELUGE,
167
+ message: `Failed to label ${name} (${infoHash}) as ${label}`,
168
+ });
169
+ }
138
170
  }
139
171
  /**
140
172
  * injects a torrent into deluge client
141
173
  */
142
- async inject(newTorrent, searchee, path) {
174
+ async inject(newTorrent, searchee, decision, path) {
143
175
  try {
144
176
  let torrentInfo;
145
- const { duplicateCategories } = getRuntimeConfig();
146
177
  if (searchee.infoHash) {
147
178
  torrentInfo = await this.getTorrentInfo(searchee);
148
179
  if (!torrentInfo.complete) {
@@ -156,28 +187,33 @@ export default class Deluge {
156
187
  });
157
188
  return InjectionResult.FAILURE;
158
189
  }
159
- const params = this.formatData(`${newTorrent.getFileSystemSafeName()}.cross-seed.torrent`, newTorrent.encode().toString("base64"), path ? path : torrentInfo.save_path, !!searchee.infoHash);
190
+ const torrentFileName = `${newTorrent.getFileSystemSafeName()}.cross-seed.torrent`;
191
+ const encodedTorrentData = newTorrent.encode().toString("base64");
192
+ const torrentPath = path ? path : torrentInfo.save_path;
193
+ const params = this.formatData(torrentFileName, encodedTorrentData, torrentPath, decision);
160
194
  const addResult = await this.call("core.add_torrent_file", params);
161
- if (addResult.result) {
162
- const { dataCategory } = getRuntimeConfig();
163
- await this.setLabel(newTorrent.infoHash, searchee.path
164
- ? dataCategory
165
- : torrentInfo.label
166
- ? duplicateCategories
167
- ? torrentInfo.label.endsWith(".cross-seed")
168
- ? torrentInfo.label
169
- : `${torrentInfo.label}.cross-seed`
170
- : torrentInfo.label
171
- : this.delugeLabel);
195
+ const addResponse = typeof addResult.error?.message === "string"
196
+ ? addResult.error
197
+ : addResult.result;
198
+ if (typeof addResponse === "string") {
199
+ await this.setLabel(newTorrent.name, newTorrent.infoHash, this.calculateLabel(searchee, torrentInfo));
200
+ if (shouldRecheck(decision)) {
201
+ // when paused, libtorrent doesnt start rechecking
202
+ // leaves torrent ready to download - ~99%
203
+ await wait(1000);
204
+ await this.call("core.force_recheck", [
205
+ [newTorrent.infoHash],
206
+ ]);
207
+ }
172
208
  return InjectionResult.SUCCESS;
173
209
  }
174
- else if (addResult.error.message.includes("already")) {
210
+ else if (addResponse?.message.includes("already")) {
175
211
  return InjectionResult.ALREADY_EXISTS;
176
212
  }
177
- else if (addResult.error.message) {
213
+ else if (addResponse) {
178
214
  logger.debug({
179
215
  label: Label.DELUGE,
180
- message: `Injection failed: ${addResult.error.message}`,
216
+ message: `Injection failed: ${addResponse}`,
181
217
  });
182
218
  return InjectionResult.FAILURE;
183
219
  }
@@ -189,38 +225,56 @@ export default class Deluge {
189
225
  return InjectionResult.FAILURE;
190
226
  }
191
227
  }
192
- catch (injectResult) {
193
- if (injectResult.includes("label.set_torrent")) {
194
- logger.warning({
195
- label: Label.DELUGE,
196
- message: `Labeling failure: ${newTorrent.name} (${newTorrent.infoHash})`,
197
- });
198
- return InjectionResult.SUCCESS;
199
- }
200
- else {
201
- logger.error({
202
- label: Label.DELUGE,
203
- message: `Injection failed: ${injectResult}`,
204
- });
205
- logger.debug(injectResult);
206
- return InjectionResult.FAILURE;
207
- }
228
+ catch (error) {
229
+ logger.error({
230
+ label: Label.DELUGE,
231
+ message: `Injection failed: ${error}`,
232
+ });
233
+ logger.debug(error);
234
+ return InjectionResult.FAILURE;
208
235
  }
209
236
  }
210
237
  /**
211
238
  * formats the json for rpc calls to inject
212
239
  */
213
- formatData(filename, filedump, path, isTorrent) {
240
+ formatData(filename, filedump, path, decision) {
241
+ const toRecheck = shouldRecheck(decision);
214
242
  return [
215
243
  filename,
216
244
  filedump,
217
245
  {
218
- add_paused: isTorrent ? false : !getRuntimeConfig().skipRecheck,
219
- seed_mode: isTorrent ? true : getRuntimeConfig().skipRecheck,
246
+ add_paused: toRecheck,
247
+ seed_mode: !toRecheck,
220
248
  download_location: path,
221
249
  },
222
250
  ];
223
251
  }
252
+ /**
253
+ * returns directory of an infohash in deluge as a string
254
+ */
255
+ async getDownloadDir(searchee) {
256
+ let torrent, response;
257
+ const params = [["save_path", "progress"], { hash: searchee.infoHash }];
258
+ try {
259
+ response = await this.call("web.update_ui", params);
260
+ }
261
+ catch (e) {
262
+ return resultOfErr("UNKNOWN_ERROR");
263
+ }
264
+ if (response.result.torrents) {
265
+ torrent = response.result.torrents?.[searchee.infoHash];
266
+ }
267
+ else {
268
+ return resultOfErr("UNKNOWN_ERROR");
269
+ }
270
+ if (torrent === undefined) {
271
+ return resultOfErr("NOT_FOUND");
272
+ }
273
+ else if (response.result.torrents?.[searchee.infoHash].progress !== 100) {
274
+ return resultOfErr("TORRENT_NOT_COMPLETE");
275
+ }
276
+ return resultOf(torrent.save_path);
277
+ }
224
278
  /**
225
279
  * returns information needed to complete/validate injection
226
280
  */
@@ -260,7 +314,6 @@ export default class Deluge {
260
314
  message: `Failed to fetch torrent data: ${searchee.name} - (${searchee.infoHash})`,
261
315
  });
262
316
  logger.debug(e);
263
- // @ts-expect-error needs es2022 target (tsconfig)
264
317
  throw new Error("web.update_ui: failed to fetch data from client", {
265
318
  cause: e,
266
319
  });