mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
根因:LLRT 的 fs.readdir 返回字符串数组而非 Dirent 对象, entry.isFile() 抛 TypeError 被 catch 静默吞掉, 导致 evictIfNeeded 和 temp_cleaner 从未执行(线上堆积 108 个文件 992M)。 修复: - node.ts: readdir 改为先拿文件名再 stat 判断 - temp_cleaner.ts: catch 块加日志不再静默吞错误 同时包含: - font-config.json homepage 链接修复(删除 3 个 404,修正 2 个) - FontDetail 字符预览改为可实时编辑 - 添加 scripts/bench.mjs 压测脚本
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { implInterface } from "../interface";
|
||
import { stat as fsStat, readFile, writeFile, readdir as fsReaddir, mkdir, unlink } from "fs/promises";
|
||
|
||
implInterface({
|
||
async stat(path) {
|
||
const r = await fsStat(path);
|
||
return r;
|
||
},
|
||
readFile(path) {
|
||
return readFile(path);
|
||
},
|
||
writeFile(path, data) {
|
||
return writeFile(path, data);
|
||
},
|
||
/**
|
||
* readdir 返回 { name, isFile } 适配对象
|
||
*
|
||
* 不用 withFileTypes:LLRT 的 fs.readdir 不支持该选项,
|
||
* 返回的是纯字符串数组而非 Dirent 对象,调用 entry.isFile() 会抛 TypeError。
|
||
* 统一用 stat 判断,Node 和 LLRT 都兼容。
|
||
*/
|
||
async readdir(path) {
|
||
const names = await fsReaddir(path);
|
||
const results: { isFile: () => boolean; name: string }[] = [];
|
||
for (const name of names) {
|
||
try {
|
||
const s = await fsStat(path + "/" + name);
|
||
results.push({ name, isFile: () => s.isFile() });
|
||
} catch {
|
||
/** stat 失败(符号链接断裂等)跳过 */
|
||
}
|
||
}
|
||
return results;
|
||
},
|
||
async mkdir(path) {
|
||
await mkdir(path, { recursive: true });
|
||
},
|
||
unlink(path) {
|
||
return unlink(path);
|
||
},
|
||
});
|