mirror of
https://github.com/2234839/web-font.git
synced 2026-04-30 05:08:14 +08:00
- 前端UI重构:字体选择器、文本预览、CSS输出+复制、下载字体、上传区域 - 后端新增API:/api/fonts(列出字体)、/api/config(公开配置)、/api/upload(上传字体) - 字体查找支持模糊匹配(精确 > 前缀 > 包含) - 上传功能分两种模式:临时上传(ENV开关,FIFO上限10个)和管理员上传(API Key认证) - 新增multipart解析器、配置模块、文件系统抽象(writeFile/readdir/mkdir/unlink) - 后端启动时等待运行时初始化完成,确保接口可用 - dev-all.ts后端启用tsx watch模式自动重载 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
export let stat: (path: string) => Promise<{
|
|
isFile: () => boolean;
|
|
size: number;
|
|
}>;
|
|
|
|
export let readFile: (path: string) => Promise<Uint8Array>;
|
|
|
|
export let writeFile: (path: string, data: Uint8Array) => Promise<void>;
|
|
|
|
export let readdir: (path: string) => Promise<{
|
|
isFile: () => boolean;
|
|
name: string;
|
|
}[]>;
|
|
|
|
export let mkdir: (path: string) => Promise<void>;
|
|
|
|
export let unlink: (path: string) => Promise<void>;
|
|
|
|
export const implInterface = (options: {
|
|
stat: typeof stat;
|
|
readFile: typeof readFile;
|
|
writeFile: typeof writeFile;
|
|
readdir: typeof readdir;
|
|
mkdir: typeof mkdir;
|
|
unlink: typeof unlink;
|
|
}) => {
|
|
stat = options.stat;
|
|
readFile = options.readFile;
|
|
writeFile = options.writeFile;
|
|
readdir = options.readdir;
|
|
mkdir = options.mkdir;
|
|
unlink = options.unlink;
|
|
};
|
|
|
|
export function path_join(...paths: string[]) {
|
|
// 定义路径分隔符
|
|
const sep = "/";
|
|
|
|
// 函数用来移除路径片段两端的斜杠
|
|
function trimSlashes(p: string) {
|
|
return p.replace(/\/+$/, "").replace(/^\/+/, "");
|
|
}
|
|
|
|
// 处理路径片段
|
|
let result = paths
|
|
.map((path) => trimSlashes(path)) // 移除每个路径片段的前后斜杠
|
|
.filter(Boolean) // 过滤掉空片段
|
|
.join(sep); // 使用分隔符连接路径片段
|
|
|
|
// 如果最终路径为空,返回根路径
|
|
if (!result) return sep;
|
|
|
|
// 确保路径以分隔符开头
|
|
if (paths[0] && paths[0].startsWith(sep)) {
|
|
result = sep + result;
|
|
}
|
|
|
|
return result;
|
|
}
|