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
|
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)
|
const task = globalThis.relic_core.tasks.find((task) => task.id === pkg_id)
|
||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
BaseLog.warn(`Task not found [${pkg_id}]`)
|
BaseLog.warn(`Task not found [${pkg_id}]`)
|
||||||
await task.abortController.abort()
|
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)
|
await UninstallHandler(pkg_id)
|
||||||
|
@ -30,11 +30,11 @@ export default async function downloadTorrent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = new aria2({
|
const client = new aria2({
|
||||||
host: 'localhost',
|
host: "localhost",
|
||||||
port: 6800,
|
port: 6800,
|
||||||
secure: false,
|
secure: false,
|
||||||
secret: '',
|
secret: "",
|
||||||
path: '/jsonrpc'
|
path: "/jsonrpc"
|
||||||
})
|
})
|
||||||
|
|
||||||
await client.open()
|
await client.open()
|
||||||
@ -52,13 +52,14 @@ export default async function downloadTorrent(
|
|||||||
onStart()
|
onStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof taskId === "string") {
|
async function stopDownload() {
|
||||||
// TODO: Unregister me when task is cancelled or finished
|
await client.call("remove", downloadId)
|
||||||
global._relic_eventBus.once(`task:cancel:${taskId}`, () => {
|
clearInterval(progressInterval)
|
||||||
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 () => {
|
progressInterval = setInterval(async () => {
|
||||||
@ -104,17 +105,15 @@ export default async function downloadTorrent(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(progressInterval)
|
|
||||||
|
|
||||||
if (typeof onDone === "function") {
|
if (typeof onDone === "function") {
|
||||||
onDone()
|
onDone()
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve({
|
stopDownload()
|
||||||
|
|
||||||
|
return resolve({
|
||||||
downloadId,
|
downloadId,
|
||||||
})
|
})
|
||||||
|
|
||||||
return null
|
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on("onDownloadError", ([{ gid }]) => {
|
client.on("onDownloadError", ([{ gid }]) => {
|
||||||
@ -122,17 +121,22 @@ export default async function downloadTorrent(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(progressInterval)
|
stopDownload()
|
||||||
|
|
||||||
if (typeof onError === "function") {
|
if (typeof onError === "function") {
|
||||||
onError()
|
onError()
|
||||||
} else {
|
|
||||||
reject()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return reject()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
await client.call("remove", downloadId)
|
await client.call("remove", downloadId)
|
||||||
|
|
||||||
|
if (taskId) {
|
||||||
|
global._relic_eventBus.off(`task:cancel:${taskId}`, stopDownload)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return downloadId
|
return downloadId
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user