mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 07:28:37 +08:00
fix(progress): 修复重复点击时,progressEventSource 被覆盖会产生孤儿事件的情况。
This commit is contained in:
@@ -188,6 +188,11 @@ async function handleTransferLog(logid: number, background: boolean = false) {
|
|||||||
|
|
||||||
// 使用SSE监听加载进度
|
// 使用SSE监听加载进度
|
||||||
function startLoadingProgress() {
|
function startLoadingProgress() {
|
||||||
|
// 在创建新连接之前,先确保任何可能存在的旧连接都被关闭了,防止因快速重复点击而产生孤儿连接。
|
||||||
|
if (progressEventSource.value) {
|
||||||
|
progressEventSource.value.close()
|
||||||
|
}
|
||||||
|
|
||||||
progressText.value = t('dialog.reorganize.processing')
|
progressText.value = t('dialog.reorganize.processing')
|
||||||
progressEventSource.value = new EventSource(`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`)
|
progressEventSource.value = new EventSource(`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`)
|
||||||
progressEventSource.value.onmessage = event => {
|
progressEventSource.value.onmessage = event => {
|
||||||
@@ -197,6 +202,13 @@ function startLoadingProgress() {
|
|||||||
progressValue.value = progress.value
|
progressValue.value = progress.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发生错误时,也确保连接被关闭,避免重试等意外行为
|
||||||
|
progressEventSource.value.onerror = () => {
|
||||||
|
if (progressEventSource.value) {
|
||||||
|
progressEventSource.value.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止监听加载进度
|
// 停止监听加载进度
|
||||||
|
|||||||
Reference in New Issue
Block a user