export const OSS_MIGRATION_CONFIG_KEY = "oss_image_migration_config"; export type OssImageMigrationConfig = { enabled: boolean; preferAliyunForUploads: boolean; sourceStorageConfigId: string; targetStorageConfigId: string; migrateAfterHours: number; cleanupAfterHours: number; batchSize: number; }; export const defaultOssImageMigrationConfig: OssImageMigrationConfig = { enabled: true, preferAliyunForUploads: true, sourceStorageConfigId: "", targetStorageConfigId: "", migrateAfterHours: 48, cleanupAfterHours: 72, batchSize: 20, }; export function normalizeOssImageMigrationConfig( value: unknown ): OssImageMigrationConfig { const raw = value && typeof value === "object" && !Array.isArray(value) ? (value as Record) : {}; const migrateAfterHours = Number(raw.migrateAfterHours); const cleanupAfterHours = Number(raw.cleanupAfterHours); const batchSize = Number(raw.batchSize); const normalizedMigrateAfterHours = Number.isFinite(migrateAfterHours) && migrateAfterHours >= 1 ? Math.min(720, Math.round(migrateAfterHours)) : defaultOssImageMigrationConfig.migrateAfterHours; const normalizedCleanupAfterHours = Number.isFinite(cleanupAfterHours) && cleanupAfterHours > normalizedMigrateAfterHours ? Math.min(1440, Math.round(cleanupAfterHours)) : Math.max( defaultOssImageMigrationConfig.cleanupAfterHours, normalizedMigrateAfterHours + 1 ); const normalizedBatchSize = Number.isFinite(batchSize) && batchSize >= 1 ? Math.min(100, Math.round(batchSize)) : defaultOssImageMigrationConfig.batchSize; return { enabled: raw.enabled !== false, preferAliyunForUploads: raw.preferAliyunForUploads !== false, sourceStorageConfigId: String(raw.sourceStorageConfigId || "").trim(), targetStorageConfigId: String(raw.targetStorageConfigId || "").trim(), migrateAfterHours: normalizedMigrateAfterHours, cleanupAfterHours: normalizedCleanupAfterHours, batchSize: normalizedBatchSize, }; }