fix(dos): 修复红红的ci
This commit is contained in:
1 parent
959a175109
commit
f069843c43
4 files changed
+55
-20
No files matched your search
@@ -1,21 +1,30 @@
|
||||
import path from 'path';
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
export function callsites () {
|
||||
const _prepareStackTrace = Error.prepareStackTrace
|
||||
try {
|
||||
let result: NodeJS.CallSite[] = []
|
||||
Error.prepareStackTrace = (_, callSites) => {
|
||||
const callSitesWithoutCurrent = callSites.slice(1)
|
||||
result = callSitesWithoutCurrent
|
||||
return callSitesWithoutCurrent
|
||||
}
|
||||
|
||||
new Error().stack
|
||||
return result
|
||||
} finally {
|
||||
Error.prepareStackTrace = _prepareStackTrace
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(global, '__dirname', {
|
||||
get() {
|
||||
const err = new Error();
|
||||
const stack = err.stack?.split('\n') || [];
|
||||
let callerFile = '';
|
||||
// 遍历错误堆栈,跳过当前文件所在行
|
||||
// 注意:堆栈格式可能不同,请根据实际环境调整索引及正则表达式
|
||||
for (const line of stack) {
|
||||
const match = line.match(/\((.*):\d+:\d+\)/);
|
||||
if (match?.[1]) {
|
||||
callerFile = match[1];
|
||||
if (!callerFile.includes('init-dynamic-dirname.ts')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
get () {
|
||||
const sites = callsites()
|
||||
const file = sites?.[1]?.getFileName()
|
||||
if (file) {
|
||||
return path.dirname(fileURLToPath(file))
|
||||
}
|
||||
return callerFile ? path.dirname(callerFile) : '';
|
||||
return ''
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import './init-dynamic-dirname';
|
||||
// import './init-dynamic-dirname';
|
||||
import { WebUiConfig } from '@/webui';
|
||||
import { AuthHelper } from '../helper/SignToken';
|
||||
import { LogWrapper } from '@/common/log';
|
||||
|
||||
@@ -66,7 +66,15 @@ export const createDiskStorage = (uploadPath: string) => {
|
||||
};
|
||||
|
||||
export const createDiskUpload = (uploadPath: string) => {
|
||||
const upload = multer({ storage: createDiskStorage(uploadPath) }).array('files');
|
||||
const upload = multer({
|
||||
storage: createDiskStorage(uploadPath),
|
||||
limits: {
|
||||
fileSize: 100 * 1024 * 1024, // 100MB 文件大小限制
|
||||
files: 20, // 最多同时上传20个文件
|
||||
fieldSize: 1024 * 1024, // 1MB 字段大小限制
|
||||
fields: 10 // 最多10个字段
|
||||
}
|
||||
}).array('files');
|
||||
return upload;
|
||||
};
|
||||
|
||||
@@ -76,6 +84,18 @@ const diskUploader = (req: Request, res: Response) => {
|
||||
createDiskUpload(uploadPath)(req, res, (error) => {
|
||||
if (error) {
|
||||
// 错误处理
|
||||
if (error.code === 'LIMIT_FILE_SIZE') {
|
||||
return reject(new Error('文件大小超过限制(最大100MB)'));
|
||||
}
|
||||
if (error.code === 'LIMIT_FILE_COUNT') {
|
||||
return reject(new Error('文件数量超过限制(最多20个文件)'));
|
||||
}
|
||||
if (error.code === 'LIMIT_FIELD_VALUE') {
|
||||
return reject(new Error('字段值大小超过限制'));
|
||||
}
|
||||
if (error.code === 'LIMIT_FIELD_COUNT') {
|
||||
return reject(new Error('字段数量超过限制'));
|
||||
}
|
||||
return reject(error);
|
||||
}
|
||||
return resolve(true);
|
||||
|
||||
Reference in new issue
Block a user