mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 02:24:18 +00:00
improve torrent cancelationm
This commit is contained in:
parent
21152ac248
commit
1e74f49e4e
@ -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
|
||||
})
|
||||
|
||||
}
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user