diff --git a/README.en.md b/README.en.md index e92edae..b76190e 100644 --- a/README.en.md +++ b/README.en.md @@ -123,6 +123,8 @@ services: - ENABLE_TEMP_UPLOAD=true - ADMIN_API_KEY=your-secret-key - SUBSET_CACHE_MAX_SIZE=10485760 + # Temp font retention (seconds), auto-deleted if unused. Default: 10800 (3h) + - TEMP_RETENTION_SECONDS=10800 ``` ## API Reference diff --git a/README.md b/README.md index 6391770..244fe5b 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ services: - ENABLE_TEMP_UPLOAD=true - ADMIN_API_KEY=your-secret-key - SUBSET_CACHE_MAX_SIZE=10485760 + # 临时字体保留时限(秒),超时未使用自动删除,默认 10800(3小时) + - TEMP_RETENTION_SECONDS=10800 ``` ## API diff --git a/backend/config.ts b/backend/config.ts index 687e4c7..dbb4f90 100644 --- a/backend/config.ts +++ b/backend/config.ts @@ -15,8 +15,8 @@ export const tempMaxFiles = parseInt(env.TEMP_MAX_FILES ?? "10", 10) || 10; /** 临时上传目录总体积上限(字节),默认 200MB */ export const tempMaxTotalSize = parseInt(env.TEMP_MAX_TOTAL_SIZE ?? `${200 * 1024 * 1024}`, 10) || 200 * 1024 * 1024; -/** 临时字体保留时限(小时),超过后若无人使用则自动删除 */ -export const tempRetentionHours = parseFloat(env.TEMP_RETENTION_HOURS ?? "3") || 3; +/** 临时字体保留时限(秒),超过后若无人使用则自动删除 */ +export const tempRetentionSeconds = parseInt(env.TEMP_RETENTION_SECONDS ?? "10800", 10) || 10800; /** 字体裁剪结果内存缓存容量上限(字节),默认 10MB */ export const subsetCacheMaxSize = parseInt(env.SUBSET_CACHE_MAX_SIZE ?? `${10 * 1024 * 1024}`, 10) || 10 * 1024 * 1024; diff --git a/backend/routes/config.ts b/backend/routes/config.ts index fd0b0dc..f533bef 100644 --- a/backend/routes/config.ts +++ b/backend/routes/config.ts @@ -1,5 +1,5 @@ import { jsonResponse } from "../shared"; -import { enableTempUpload, adminApiKey, tempRetentionHours } from "../config"; +import { enableTempUpload, adminApiKey, tempRetentionSeconds } from "../config"; /** GET /api/config — 返回公开配置 */ export async function handleGetConfig(req: Request, _res: Response) { @@ -9,8 +9,8 @@ export async function handleGetConfig(req: Request, _res: Response) { enableTempUpload, adminUploadEnabled: !!adminApiKey, supportedOutTypes: ["woff2", "ttf"], - /** 临时字体保留时限(小时) */ - tempRetentionHours, + /** 临时字体保留时限(秒) */ + tempRetentionSeconds, }), }; } diff --git a/backend/temp_cleaner.ts b/backend/temp_cleaner.ts index ae85fc2..c79075e 100644 --- a/backend/temp_cleaner.ts +++ b/backend/temp_cleaner.ts @@ -7,7 +7,7 @@ * 清理周期 = 保留时限的一半(最少 5 分钟),避免过于频繁的扫描。 */ import { readdir, stat, unlink, path_join } from "./interface"; -import { tempRetentionHours } from "./config"; +import { tempRetentionSeconds } from "./config"; /** 临时字体目录 */ const TEMP_DIR = "font/temp"; @@ -33,7 +33,7 @@ export function markFontUsed(fontPath: string): void { */ async function cleanOnce(): Promise { const now = Date.now(); - const retentionMs = tempRetentionHours * 3600_000; + const retentionMs = tempRetentionSeconds * 1000; let entries: Array<{ name: string; isFile: () => boolean }>; try { @@ -64,7 +64,7 @@ async function cleanOnce(): Promise { } /** 清理周期:保留时限的一半,最少 5 分钟 */ -const CLEAN_INTERVAL = Math.max(tempRetentionHours * 1800_000, 300_000); +const CLEAN_INTERVAL = Math.max(tempRetentionSeconds * 500, 300_000); /** * 启动定时清理器。 @@ -72,7 +72,7 @@ const CLEAN_INTERVAL = Math.max(tempRetentionHours * 1800_000, 300_000); */ export function startTempCleaner(): void { const intervalSec = Math.round(CLEAN_INTERVAL / 1000); - console.log(`[temp-cleaner] 启动,保留时限 ${tempRetentionHours}h,清理周期 ${intervalSec}s`); + console.log(`[temp-cleaner] 启动,保留时限 ${tempRetentionSeconds}s,清理周期 ${intervalSec}s`); /** 首次延迟 60 秒 */ setTimeout(() => { diff --git a/src/UploadSection.vue b/src/UploadSection.vue index 6da611c..26bc866 100644 --- a/src/UploadSection.vue +++ b/src/UploadSection.vue @@ -82,8 +82,14 @@ function onFileSelect(e: Event, target: ReturnType) {
{{ t('guestUpload') }}
{{ t('guestUploadDesc') }} - - (保留时限 {{ config.tempRetentionHours }} 小时) + + (保留时限 {{ + config.tempRetentionSeconds >= 3600 + ? Math.round(config.tempRetentionSeconds / 3600 * 10) / 10 + ' 小时' + : config.tempRetentionSeconds >= 60 + ? Math.round(config.tempRetentionSeconds / 60) + ' 分钟' + : config.tempRetentionSeconds + ' 秒' + }})
diff --git a/src/api.ts b/src/api.ts index 8ec52f1..0a08a83 100644 --- a/src/api.ts +++ b/src/api.ts @@ -9,8 +9,8 @@ export interface ServerConfig { enableTempUpload: boolean; adminUploadEnabled: boolean; supportedOutTypes: ("woff2" | "ttf")[]; - /** 临时字体保留时限(小时) */ - tempRetentionHours?: number; + /** 临时字体保留时限(秒) */ + tempRetentionSeconds?: number; } export interface UploadResult {