From d87bc6fd5a83c713bb26f497fdb35fd8d9428f10 Mon Sep 17 00:00:00 2001 From: admin <362324317@qq.com> Date: Sun, 17 May 2026 17:26:45 +0800 Subject: [PATCH] =?UTF-8?q?v0.3.21:=20=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: 1. refreshAllStorageInfo 只过滤 quark, 百度等其他网盘永远不会刷新 2. 主调度器硬编码 60 分钟, 未读取 storage_refresh_interval 配置(用户设的180分钟) 3. 条件检查用 totalBytes/usedBytes, 百度返回对象无此字段 → 永远跳过 修复: - refreshAllStorageInfo: 改为驱动注册表模式, 支持 quark+baidu, 兼容不同驱动返回格式 - main.ts: 用 setTimeout 链替代 setInterval, 每次动态读 storage_refresh_interval, 修改后无需重启即生效 --- VERSION | 2 +- source_clean/VERSION | 2 +- source_clean/src/cloud/cloud.service.ts | 54 +++++++++++++++++++++---- source_clean/src/main.ts | 24 +++++++++-- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/VERSION b/VERSION index f9a4b5f..dfdc368 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.20 +0.3.21 diff --git a/source_clean/VERSION b/source_clean/VERSION index f9a4b5f..dfdc368 100644 --- a/source_clean/VERSION +++ b/source_clean/VERSION @@ -1 +1 @@ -0.3.20 +0.3.21 diff --git a/source_clean/src/cloud/cloud.service.ts b/source_clean/src/cloud/cloud.service.ts index 9e02068..0bee9c5 100644 --- a/source_clean/src/cloud/cloud.service.ts +++ b/source_clean/src/cloud/cloud.service.ts @@ -327,23 +327,63 @@ export function cleanupOldSaveRecords(): void { // ── Storage Refresh ─────────────────────────────────────────────── +/** + * Refresh storage info for all active cloud configs that have a getStorageInfo method. + * Supports quark and baidu drivers. + */ export async function refreshAllStorageInfo(): Promise { - const configs = getActiveCloudConfigs().filter(c => c.cloud_type === 'quark' && c.cookie); + const configs = getActiveCloudConfigs().filter(c => c.cookie); if (configs.length === 0) return; + // Driver mapping: cloud_type → { module, class } + const DRIVER_REGISTRY: Record = { + quark: { module: './drivers/quark.driver', cls: 'QuarkDriver' }, + baidu: { module: './drivers/baidu.driver', cls: 'BaiduDriver' }, + }; + for (const cfg of configs) { + const entry = DRIVER_REGISTRY[cfg.cloud_type]; + if (!entry) continue; // no getStorageInfo support for this cloud type + try { - const { QuarkDriver } = require('./drivers/quark.driver'); - const driver = new QuarkDriver({ cookie: cfg.cookie, nickname: cfg.nickname }); - const storage = await driver.getStorageInfo(); - if (storage.totalBytes > 0 || storage.usedBytes > 0) { + const mod = require(entry.module); + const Driver = mod[entry.cls]; + if (!Driver) continue; + + const driver = new Driver({ cookie: cfg.cookie, nickname: cfg.nickname }); + + // Try getStorageInfo first (quark cleanup API), fallback to getStorageInfoQuick + let storage: any; + try { + storage = await driver.getStorageInfo(); + } catch { + if (typeof driver.getStorageInfoQuick === 'function') { + storage = await driver.getStorageInfoQuick(); + } else { + continue; + } + } + + if (!storage) continue; + + // Get formatted strings — some drivers return {used, total, usedBytes, totalBytes} + const used = storage.used || '计算中...'; + const total = storage.total || '-'; + + // Only update if we got meaningful data + const hasRealData = + (storage.totalBytes > 0 || storage.usedBytes > 0) || // quark returns these + (used !== '-' && used !== '0 B' && used !== '计算中...'); // baidu check + + if (hasRealData) { const db = getDb(); db.prepare( `UPDATE cloud_configs SET storage_used = ?, storage_total = ? WHERE id = ?` - ).run(storage.used, storage.total, cfg.id); + ).run(used, total, cfg.id); + console.log(`[Storage] Refreshed ${cfg.cloud_type}#${cfg.id}: ${used} / ${total}`); } } catch (err: any) { - console.error(`[Storage] Failed to refresh quark#${cfg.id}:`, err.message); + console.error(`[Storage] Failed to refresh ${cfg.cloud_type}#${cfg.id}:`, err.message); } } } diff --git a/source_clean/src/main.ts b/source_clean/src/main.ts index 7e91d81..178677f 100755 --- a/source_clean/src/main.ts +++ b/source_clean/src/main.ts @@ -178,10 +178,28 @@ async function start(): Promise { setInterval(() => { checkAndRunScheduledCleanup().catch(err => console.error('[Cleanup] Scheduler error:', err.message)); }, CLEANUP_INTERVAL); setTimeout(() => { checkAndRunScheduledCleanup().catch(err => console.error('[Cleanup] Initial check error:', err.message)); }, 30000); - // Storage info refresh scheduler — every 60 minutes - const STORAGE_REFRESH_INTERVAL = 60 * 60 * 1000; - setInterval(() => { refreshAllStorageInfo().catch(err => console.error('[Storage] Refresh error:', err.message)); }, STORAGE_REFRESH_INTERVAL); + // Storage info refresh scheduler — dynamic interval from system_configs.storage_refresh_interval + // Uses setTimeout chain so interval changes take effect without restart + let storageRefreshTimer: NodeJS.Timeout | null = null; + const scheduleStorageRefresh = () => { + if (storageRefreshTimer) clearTimeout(storageRefreshTimer); + let intervalMinutes = 180; // default + try { + const { getSystemConfig } = require('./admin/system-config.service'); + const val = getSystemConfig('storage_refresh_interval'); + if (val) { const n = parseInt(val, 10); if (n >= 5 && n <= 1440) intervalMinutes = n; } + } catch {} + const ms = intervalMinutes * 60 * 1000; + console.log(`[Storage] Next refresh in ${intervalMinutes} minutes`); + storageRefreshTimer = setTimeout(() => { + refreshAllStorageInfo().catch(err => console.error('[Storage] Refresh error:', err.message)); + scheduleStorageRefresh(); // re-schedule with possibly updated interval + }, ms); + }; + // First run 60s after startup setTimeout(() => { refreshAllStorageInfo().catch(err => console.error('[Storage] Initial refresh error:', err.message)); }, 60000); + // Schedule first periodic refresh (delay = configured interval) + setTimeout(() => scheduleStorageRefresh(), 60000); // Daily Report scheduler — check every 60 seconds