mirror of
https://github.com/2234839/web-font.git
synced 2026-05-19 21:08:11 +08:00
- 新增通用 LruCache 类,支持按条目数/字节容量两种淘汰策略 - 字体裁剪结果 LRU 内存缓存(默认 10MB,X-Cache 响应头标识命中) - 新增 GET /api/stats 运行时统计接口 - 前端统计面板(10s 轮询,页面不可见时暂停) - API handler 拆分到 routes/ 目录,提取 shared.ts 共享模块 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
22 lines
656 B
TypeScript
22 lines
656 B
TypeScript
import { jsonResponse, parseUrl } from "../shared";
|
|
import { readdir, stat } from "../interface";
|
|
import { fontDirs } from "../config";
|
|
|
|
/** GET /api/fonts — 列出所有可用字体 */
|
|
export async function handleListFonts(req: Request, res: Response) {
|
|
const allFonts: Array<{ name: string; dir: string }> = [];
|
|
|
|
for (const dir of fontDirs) {
|
|
try {
|
|
const entries = await readdir(dir);
|
|
for (const entry of entries) {
|
|
if (entry.isFile() && /\.(ttf|otf|woff|woff2)$/i.test(entry.name)) {
|
|
allFonts.push({ name: entry.name, dir });
|
|
}
|
|
}
|
|
} catch {}
|
|
}
|
|
|
|
return { req, res: jsonResponse(allFonts) };
|
|
}
|