feat: add real-time files watch for LibraryView

Implement comprehensive monitoring system:
- Watch for new registered files (5s interval)
- Detect file status changes (registered → processing → completed)
- Monitor file additions/removals

Functions added:
- startFilesWatch(): Poll get_files API every 5s
- stopFilesWatch(): Clean up interval

LibraryView integration:
- Enable on mount
- Disable on unmount

Enables cross-machine monitoring: one operates, another watches changes
This commit is contained in:
2026-07-24 21:49:06 +08:00
parent 1fd6312f7e
commit 55d0216083
2 changed files with 48 additions and 3 deletions

View File

@@ -352,6 +352,7 @@ const loadingFileStats = new Set<string>()
let statsRefreshInterval: ReturnType<typeof setInterval> | null = null
let processingPollInterval: ReturnType<typeof setInterval> | null = null
let filesWatchInterval: ReturnType<typeof setInterval> | null = null
export function startStatsAutoRefresh() {
if (statsRefreshInterval) return
@@ -389,6 +390,50 @@ export function stopProcessingFilesPolling() {
}
}
export function startFilesWatch() {
if (filesWatchInterval) return
filesWatchInterval = setInterval(async () => {
try {
const result = await apiCall('get_files', { args: { pageSize: 500 } })
const newFiles = Array.isArray(result) ? result : []
// Check for new files
const oldUuids = new Set(filesCache.value.map((f: any) => f.file_uuid).filter(Boolean))
const newUuids = newFiles.map((f: any) => f.file_uuid).filter(Boolean)
// Detect new registered files
const added = newUuids.filter((uuid: string) => !oldUuids.has(uuid))
const removed = Array.from(oldUuids).filter((uuid: string) => !newUuids.includes(uuid))
if (added.length > 0 || removed.length > 0) {
filesCache.value = newFiles
}
// Check status changes for existing files
for (const newFile of newFiles) {
if (!newFile.file_uuid) continue
const oldFile = filesCache.value.find((f: any) => f.file_uuid === newFile.file_uuid)
if (oldFile && oldFile.status !== newFile.status) {
// Status changed, update cache
const idx = filesCache.value.findIndex((f: any) => f.file_uuid === newFile.file_uuid)
if (idx >= 0) {
filesCache.value[idx] = newFile
}
}
}
} catch (e) {
console.error('[startFilesWatch] Error:', e)
}
}, 5000)
}
export function stopFilesWatch() {
if (filesWatchInterval) {
clearInterval(filesWatchInterval)
filesWatchInterval = null
}
}
function drainThumbQueue() {
if (activeThumbLoads >= MAX_CONCURRENT || thumbQueue.length === 0) return
activeThumbLoads++