mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
fix(reorganize): dynamically update progress SSE connection based on item path
This commit is contained in:
@@ -10,6 +10,7 @@ import { FileItem, StorageConf, TransferDirectoryConf, TransferForm } from '@/ap
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useGlobalSettingsStore } from '@/stores'
|
import { useGlobalSettingsStore } from '@/stores'
|
||||||
import { useBackgroundOptimization } from '@/composables/useBackgroundOptimization'
|
import { useBackgroundOptimization } from '@/composables/useBackgroundOptimization'
|
||||||
|
import CryptoJS from 'crypto-js'
|
||||||
|
|
||||||
// 国际化
|
// 国际化
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -200,25 +201,36 @@ function handleProgressMessage(event: MessageEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用优化的进度SSE连接
|
// 进度SSE连接
|
||||||
const progressSSE = useProgressSSE(
|
const progressSSE = ref<any>(null)
|
||||||
`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`,
|
|
||||||
handleProgressMessage,
|
|
||||||
'reorganize-progress',
|
|
||||||
progressActive,
|
|
||||||
)
|
|
||||||
|
|
||||||
// 使用SSE监听加载进度
|
// 使用SSE监听加载进度
|
||||||
function startLoadingProgress() {
|
function startLoadingProgress(key: string) {
|
||||||
progressText.value = t('dialog.reorganize.processing')
|
progressText.value = t('dialog.reorganize.processing')
|
||||||
progressActive.value = true
|
progressActive.value = true
|
||||||
progressSSE.start()
|
|
||||||
|
// 如果已经有连接,先停止
|
||||||
|
if (progressSSE.value) {
|
||||||
|
progressSSE.value.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算MD5
|
||||||
|
const keyMd5 = CryptoJS.MD5(key).toString()
|
||||||
|
const url = `${import.meta.env.VITE_API_BASE_URL}system/progress/${keyMd5}`
|
||||||
|
|
||||||
|
// 创建新的SSE连接
|
||||||
|
progressSSE.value = useProgressSSE(url, handleProgressMessage, `reorganize-progress-${keyMd5}`, progressActive)
|
||||||
|
|
||||||
|
progressSSE.value.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止监听加载进度
|
// 停止监听加载进度
|
||||||
function stopLoadingProgress() {
|
function stopLoadingProgress() {
|
||||||
progressActive.value = false
|
progressActive.value = false
|
||||||
progressSSE.stop()
|
if (progressSSE.value) {
|
||||||
|
progressSSE.value.stop()
|
||||||
|
progressSSE.value = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 整理文件
|
// 整理文件
|
||||||
@@ -228,14 +240,13 @@ async function transfer(background: boolean = false) {
|
|||||||
// 显示进度条
|
// 显示进度条
|
||||||
progressDialog.value = true
|
progressDialog.value = true
|
||||||
|
|
||||||
if (!background) {
|
|
||||||
// 开始监听进度
|
|
||||||
startLoadingProgress()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文件整理
|
// 文件整理
|
||||||
if (props.items) {
|
if (props.items) {
|
||||||
for (const item of props.items) {
|
for (const item of props.items) {
|
||||||
|
if (!background) {
|
||||||
|
// 开始监听进度
|
||||||
|
startLoadingProgress(item.path)
|
||||||
|
}
|
||||||
await handleTransfer(item, background)
|
await handleTransfer(item, background)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user