fix: 兼容获取appKey和version
This commit is contained in:
@@ -110,6 +110,7 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
||||
multiples: true, // 支持多文件上传
|
||||
uploadDir: filePath, // 上传文件存储目录
|
||||
});
|
||||
|
||||
// 解析上传的文件
|
||||
form.parse(req, async (err, fields, files) => {
|
||||
if (err) {
|
||||
@@ -122,7 +123,18 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
||||
fs.unlinkSync(file.filepath);
|
||||
});
|
||||
};
|
||||
const { appKey, version } = fields;
|
||||
let appKey, version;
|
||||
const { appKey: _appKey, version: _version } = fields;
|
||||
if (Array.isArray(_appKey)) {
|
||||
appKey = _appKey?.[0];
|
||||
} else {
|
||||
appKey = _appKey;
|
||||
}
|
||||
if (Array.isArray(_version)) {
|
||||
version = _version?.[0];
|
||||
} else {
|
||||
version = _version;
|
||||
}
|
||||
if (!appKey) {
|
||||
res.end(error('appKey is required'));
|
||||
clearFiles();
|
||||
@@ -133,6 +145,8 @@ export const uploadMiddleware = async (req: http.IncomingMessage, res: http.Serv
|
||||
clearFiles();
|
||||
return;
|
||||
}
|
||||
console.log('Appkey', appKey, version);
|
||||
|
||||
// 逐个处理每个上传的文件
|
||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
||||
const uploadResults = [];
|
||||
|
||||
Reference in New Issue
Block a user