Files
MoonTVPlus/src/lib/data-migration-progress.ts
2026-02-24 21:48:30 +08:00

51 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 存储进度信息的 Map
const progressStore = new Map<string, {
phase: string;
current: number;
total: number;
message: string;
timestamp: number;
}>();
// 清理过期的进度信息超过5分钟
setInterval(() => {
const now = Date.now();
const entries = Array.from(progressStore.entries());
for (const [key, value] of entries) {
if (now - value.timestamp > 5 * 60 * 1000) {
progressStore.delete(key);
}
}
}, 60 * 1000);
// 辅助函数:更新进度
export function updateProgress(
username: string,
operation: 'export' | 'import',
phase: string,
current: number,
total: number,
message: string
) {
const progressKey = `${username}:${operation}`;
progressStore.set(progressKey, {
phase,
current,
total,
message,
timestamp: Date.now(),
});
}
// 辅助函数:清除进度
export function clearProgress(username: string, operation: 'export' | 'import') {
const progressKey = `${username}:${operation}`;
progressStore.delete(progressKey);
}
// 辅助函数:获取进度
export function getProgress(username: string, operation: 'export' | 'import') {
const progressKey = `${username}:${operation}`;
return progressStore.get(progressKey);
}