v0.3.24: 清理设置4个后端接线 — 白名单/cookie检测/空间校准开关
补全前端4个控制项的后端实现: - cleanup_whitelist_dirs → cleanupCloudFiles + cleanupAllBySpaceThreshold 读取并传递 - cleanup_auto_refresh_storage → scheduleStorageRefresh 读取开关,false时跳过 - cleanup_verify_enabled + cleanup_verify_interval → 新增Cookie验证调度器 - CloudCleanupDriver 接口 + baidu.driver 签名同步支持 whitelistDirs 可选参数 验证: 4个key从仅前端 → 全部有后端读取模块
This commit is contained in:
@@ -20,7 +20,7 @@ interface CleanupOpResult { trashed: number; errors: string[] }
|
||||
|
||||
interface CloudCleanupDriver {
|
||||
/** Trash date folders (YYYY-MM-DD) older than `days`. */
|
||||
cleanupOldDateFolders(days: number): Promise<CleanupOpResult>;
|
||||
cleanupOldDateFolders(days: number, whitelistDirs?: string[]): Promise<CleanupOpResult>;
|
||||
/**
|
||||
* If used space exceeds thresholdPercent% of TOTAL capacity,
|
||||
* delete oldest date folders until totalBytes * deletePercent/100
|
||||
@@ -28,7 +28,7 @@ interface CloudCleanupDriver {
|
||||
* @param thresholdPercent — trigger when usage >= this % of total
|
||||
* @param deletePercent — free this % of total capacity
|
||||
*/
|
||||
cleanupBySpaceThreshold(thresholdPercent: number, deletePercent: number): Promise<CleanupOpResult>;
|
||||
cleanupBySpaceThreshold(thresholdPercent: number, deletePercent: number, whitelistDirs?: string[]): Promise<CleanupOpResult>;
|
||||
/** Permanently empty the recycle bin. */
|
||||
emptyTrash(): Promise<boolean>;
|
||||
}
|
||||
@@ -78,6 +78,13 @@ async function cleanupCloudFiles(days: number): Promise<CleanupOpResult> {
|
||||
const errors: string[] = [];
|
||||
let totalTrashed = 0;
|
||||
|
||||
// Read whitelist from system config
|
||||
let whitelist: string[] = [];
|
||||
try {
|
||||
const raw = getSystemConfig('cleanup_whitelist_dirs');
|
||||
if (raw) whitelist = JSON.parse(raw);
|
||||
} catch {}
|
||||
|
||||
for (const cfg of configs) {
|
||||
const driver = getDriverForCleanup(cfg);
|
||||
if (!driver) {
|
||||
@@ -85,7 +92,7 @@ async function cleanupCloudFiles(days: number): Promise<CleanupOpResult> {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const result = await driver.cleanupOldDateFolders(days);
|
||||
const result = await driver.cleanupOldDateFolders(days, whitelist);
|
||||
totalTrashed += result.trashed;
|
||||
errors.push(...result.errors.map(e => `[${cfg.cloud_type}#${cfg.id}] ${e}`));
|
||||
} catch (err: any) {
|
||||
@@ -109,6 +116,13 @@ async function cleanupAllBySpaceThreshold(
|
||||
const errors: string[] = [];
|
||||
let totalTrashed = 0;
|
||||
|
||||
// Read whitelist from system config
|
||||
let whitelist: string[] = [];
|
||||
try {
|
||||
const raw = getSystemConfig('cleanup_whitelist_dirs');
|
||||
if (raw) whitelist = JSON.parse(raw);
|
||||
} catch {}
|
||||
|
||||
for (const cfg of configs) {
|
||||
const driver = getDriverForCleanup(cfg);
|
||||
if (!driver) {
|
||||
@@ -116,7 +130,7 @@ async function cleanupAllBySpaceThreshold(
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const result = await driver.cleanupBySpaceThreshold(thresholdPercent, deletePercent);
|
||||
const result = await driver.cleanupBySpaceThreshold(thresholdPercent, deletePercent, whitelist);
|
||||
totalTrashed += result.trashed;
|
||||
errors.push(...result.errors.map(e => `[${cfg.cloud_type}#${cfg.id}] ${e}`));
|
||||
} catch (err: any) {
|
||||
|
||||
@@ -1105,7 +1105,7 @@ export class BaiduDriver {
|
||||
}
|
||||
}
|
||||
|
||||
async cleanupOldDateFolders(days: number): Promise<{ trashed: number; errors: string[] }> {
|
||||
async cleanupOldDateFolders(days: number, _whitelistDirs?: string[]): Promise<{ trashed: number; errors: string[] }> {
|
||||
const errors: string[] = [];
|
||||
const cutoff = new Date();
|
||||
cutoff.setDate(cutoff.getDate() - days);
|
||||
@@ -1131,7 +1131,7 @@ export class BaiduDriver {
|
||||
}
|
||||
}
|
||||
|
||||
async cleanupBySpaceThreshold(thresholdPercent: number, deletePercent: number): Promise<{ trashed: number; errors: string[] }> {
|
||||
async cleanupBySpaceThreshold(thresholdPercent: number, deletePercent: number, _whitelistDirs?: string[]): Promise<{ trashed: number; errors: string[] }> {
|
||||
const errors: string[] = [];
|
||||
try {
|
||||
const info = await this.getUserInfo();
|
||||
|
||||
Reference in New Issue
Block a user