mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 02:24:18 +00:00
fix torrent cancelation
This commit is contained in:
parent
1e74f49e4e
commit
e1d833a5f5
@ -15,15 +15,15 @@ export default async function reinstall(pkg_id) {
|
||||
return null
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
const task = globalThis.relic_core.tasks.find((task) => task.id === 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)
|
||||
|
@ -30,11 +30,11 @@ export default async function downloadTorrent(
|
||||
}
|
||||
|
||||
const client = new aria2({
|
||||
host: 'localhost',
|
||||
host: "localhost",
|
||||
port: 6800,
|
||||
secure: false,
|
||||
secret: '',
|
||||
path: '/jsonrpc'
|
||||
secret: "",
|
||||
path: "/jsonrpc"
|
||||
})
|
||||
|
||||
await client.open()
|
||||
@ -52,13 +52,14 @@ 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])
|
||||
async function stopDownload() {
|
||||
await client.call("remove", downloadId)
|
||||
clearInterval(progressInterval)
|
||||
reject()
|
||||
})
|
||||
}
|
||||
|
||||
if (taskId) {
|
||||
// TODO: Unregister me when download finish
|
||||
global._relic_eventBus.once(`task:cancel:${taskId}`, stopDownload)
|
||||
}
|
||||
|
||||
progressInterval = setInterval(async () => {
|
||||
@ -104,17 +105,15 @@ export default async function downloadTorrent(
|
||||
return false
|
||||
}
|
||||
|
||||
clearInterval(progressInterval)
|
||||
|
||||
if (typeof onDone === "function") {
|
||||
onDone()
|
||||
}
|
||||
|
||||
resolve({
|
||||
stopDownload()
|
||||
|
||||
return resolve({
|
||||
downloadId,
|
||||
})
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
client.on("onDownloadError", ([{ gid }]) => {
|
||||
@ -122,17 +121,22 @@ export default async function downloadTorrent(
|
||||
return false
|
||||
}
|
||||
|
||||
clearInterval(progressInterval)
|
||||
stopDownload()
|
||||
|
||||
if (typeof onError === "function") {
|
||||
onError()
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
|
||||
return reject()
|
||||
})
|
||||
})
|
||||
|
||||
await client.call("remove", downloadId)
|
||||
|
||||
if (taskId) {
|
||||
global._relic_eventBus.off(`task:cancel:${taskId}`, stopDownload)
|
||||
}
|
||||
|
||||
|
||||
return downloadId
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user