diff --git a/packages/core/src/generic_steps/torrent.js b/packages/core/src/generic_steps/torrent.js index 5c5edac..18c497b 100644 --- a/packages/core/src/generic_steps/torrent.js +++ b/packages/core/src/generic_steps/torrent.js @@ -8,7 +8,7 @@ export default async (pkg, step, logger, abortController) => { if (!step.magnet) { throw new Error(`Magnet is required for torrent step`) } - + if (typeof step.path === "undefined") { step.path = `.` } @@ -41,7 +41,8 @@ export default async (pkg, step, logger, abortController) => { use_id_only: true, status_text: `Downloaded ${progress.transferredString} / ${progress.totalString} | ${progress.speedString}/s`, }) - } + }, + taskId: pkg.id }) } \ No newline at end of file diff --git a/packages/core/src/handlers/cancelInstall.js b/packages/core/src/handlers/cancelInstall.js index 489b8eb..bf62a74 100644 --- a/packages/core/src/handlers/cancelInstall.js +++ b/packages/core/src/handlers/cancelInstall.js @@ -20,6 +20,10 @@ export default async function reinstall(pkg_id) { if (task) { BaseLog.warn(`Task not found [${pkg_id}]`) await task.abortController.abort() + + global._relic_eventBus.emit(`pkg:install:cancel`, pkg_id) + global._relic_eventBus.emit(`pkg:install:cancel:${pkg_id}`, pkg_id) + global._relic_eventBus.emit(`task:cancel:${pkg_id}`, pkg_id) } await UninstallHandler(pkg_id) diff --git a/packages/core/src/helpers/downloadTorrent.js b/packages/core/src/helpers/downloadTorrent.js index a64c4ef..28b024a 100644 --- a/packages/core/src/helpers/downloadTorrent.js +++ b/packages/core/src/helpers/downloadTorrent.js @@ -1,6 +1,3 @@ -import fs from "node:fs" -import path from "node:path" -import cliProgress from "cli-progress" import humanFormat from "human-format" import aria2 from "aria2" @@ -18,6 +15,7 @@ export default async function downloadTorrent( onProgress, onDone, onError, + taskId, } = {} ) { let progressInterval = null @@ -54,9 +52,17 @@ export default async function downloadTorrent( onStart() } + if (typeof taskId === "string") { + // TODO: Unregister me when task is cancelled or finished + global._relic_eventBus.once(`task:cancel:${taskId}`, () => { + client.call("remove", [downloadId]) + clearInterval(progressInterval) + reject() + }) + } + progressInterval = setInterval(async () => { const data = await client.call("tellStatus", downloadId) - const isMetadata = data.totalLength === "0" && data.status === "active" console.log(data)