Commit 787d61b9 authored by 水濑真白's avatar 水濑真白

Merge remote-tracking branch 'upstream/master' into develop

parents fed1ff8c 2a639db2
Pipeline #43215 passed with stages
in 5 minutes and 27 seconds
......@@ -189,29 +189,33 @@ const UploadToChallonge = async function () {
};
const receiveDecks = async function (files, callback) {
try {
// formidable parse() 返回的 files 通常是对象:{ fieldName: File | File[] }
// 老代码按数组 for..of 会直接抛:TypeError: files is not iterable
const fileList = Array.isArray(files)
? files
: files && typeof files === "object"
? Object.values(files).flatMap((v) => (Array.isArray(v) ? v : [v]))
: [];
const result = [];
for (const file of files) {
if (file.name.endsWith(".ydk")) {
const deck = await readDeck(file.name, file.path);
for (const f of fileList) {
const filename = (f?.originalFilename ?? f?.name ?? "");
const filepath = (f?.filepath ?? f?.path ?? "");
if (!filename || !filepath) {
result.push({ file: filename || "(unknown)", status: "上传文件信息缺失" });
continue;
}
if (filename.endsWith(".ydk")) {
const deck = await readDeck(filename, filepath);
if (deck.main.length >= 40) {
fs.createReadStream(file.path).pipe(fs.createWriteStream(config.deck_path + file.name));
result.push({
file: file.name,
status: "OK",
});
fs.createReadStream(filepath).pipe(fs.createWriteStream(config.deck_path + filename));
result.push({ file: filename, status: "OK" });
}
else {
result.push({
file: file.name,
status: "卡组不合格",
});
result.push({ file: filename, status: "卡组不合格" });
}
}
else {
result.push({
file: file.name,
status: "不是卡组文件",
});
result.push({ file: filename, status: "不是卡组文件" });
}
}
callback(null, result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment