mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 14:53:32 +08:00
feat: 临时字体保留时限改为秒为单位(TEMP_RETENTION_SECONDS)
- TEMP_RETENTION_HOURS → TEMP_RETENTION_SECONDS,默认 10800(3小时) - 前端显示自适应:秒/分钟/小时 - README docker-compose 示例同步更新
This commit is contained in:
parent
19b14f58ea
commit
abd75985b7
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
@ -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<void> {
|
||||
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<void> {
|
||||
}
|
||||
|
||||
/** 清理周期:保留时限的一半,最少 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(() => {
|
||||
|
||||
@ -82,8 +82,14 @@ function onFileSelect(e: Event, target: ReturnType<typeof useUpload>) {
|
||||
<div style="font-size: 14px; font-weight: 500; margin-bottom: 4px">{{ t('guestUpload') }}</div>
|
||||
<div style="font-size: 12px; color: #999; margin-bottom: 12px">
|
||||
{{ t('guestUploadDesc') }}
|
||||
<span v-if="config.tempRetentionHours" style="color: #1677ff">
|
||||
(保留时限 {{ config.tempRetentionHours }} 小时)
|
||||
<span v-if="config.tempRetentionSeconds" style="color: #1677ff">
|
||||
(保留时限 {{
|
||||
config.tempRetentionSeconds >= 3600
|
||||
? Math.round(config.tempRetentionSeconds / 3600 * 10) / 10 + ' 小时'
|
||||
: config.tempRetentionSeconds >= 60
|
||||
? Math.round(config.tempRetentionSeconds / 60) + ' 分钟'
|
||||
: config.tempRetentionSeconds + ' 秒'
|
||||
}})
|
||||
</span>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center">
|
||||
|
||||
@ -9,8 +9,8 @@ export interface ServerConfig {
|
||||
enableTempUpload: boolean;
|
||||
adminUploadEnabled: boolean;
|
||||
supportedOutTypes: ("woff2" | "ttf")[];
|
||||
/** 临时字体保留时限(小时) */
|
||||
tempRetentionHours?: number;
|
||||
/** 临时字体保留时限(秒) */
|
||||
tempRetentionSeconds?: number;
|
||||
}
|
||||
|
||||
export interface UploadResult {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user