mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-04 09:42:02 +08:00
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import multer from 'multer';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
import type { Request, Response } from 'express';
|
|
import { WebUiConfig } from '@/napcat-webui-backend/index';
|
|
|
|
export const webUIFontStorage = multer.diskStorage({
|
|
destination: (_, __, cb) => {
|
|
try {
|
|
const fontsPath = path.dirname(WebUiConfig.GetWebUIFontPath());
|
|
// 确保字体目录存在
|
|
fs.mkdirSync(fontsPath, { recursive: true });
|
|
cb(null, fontsPath);
|
|
} catch (error) {
|
|
// 确保错误信息被正确传递
|
|
cb(new Error(`创建字体目录失败:${(error as Error).message}`), '');
|
|
}
|
|
},
|
|
filename: (_, __, cb) => {
|
|
// 统一保存为webui.woff
|
|
cb(null, 'webui.woff');
|
|
},
|
|
});
|
|
|
|
export const webUIFontUpload = multer({
|
|
storage: webUIFontStorage,
|
|
fileFilter: (_, file, cb) => {
|
|
// 再次验证文件类型
|
|
if (!file.originalname.toLowerCase().endsWith('.woff')) {
|
|
cb(new Error('只支持WOFF格式的字体文件'));
|
|
return;
|
|
}
|
|
cb(null, true);
|
|
},
|
|
limits: {
|
|
fileSize: 40 * 1024 * 1024, // 限制40MB
|
|
},
|
|
}).single('file');
|
|
|
|
const webUIFontUploader = (req: Request, res: Response) => {
|
|
return new Promise((resolve, reject) => {
|
|
webUIFontUpload(req, res, (error) => {
|
|
if (error) {
|
|
// 错误处理
|
|
// sendError(res, error.message, true);
|
|
return reject(error);
|
|
}
|
|
return resolve(true);
|
|
});
|
|
});
|
|
};
|
|
export default webUIFontUploader;
|