Commit e25797c6 authored by 水濑真白's avatar 水濑真白

Merge remote-tracking branch 'upstream/master'

parents b6d54132 2a639db2
Pipeline #43214 failed with stages
in 100 minutes and 30 seconds
...@@ -189,29 +189,33 @@ const UploadToChallonge = async function () { ...@@ -189,29 +189,33 @@ const UploadToChallonge = async function () {
}; };
const receiveDecks = async function (files, callback) { const receiveDecks = async function (files, callback) {
try { 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 = []; const result = [];
for (const file of files) { for (const f of fileList) {
if (file.name.endsWith(".ydk")) { const filename = (f?.originalFilename ?? f?.name ?? "");
const deck = await readDeck(file.name, file.path); 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) { if (deck.main.length >= 40) {
fs.createReadStream(file.path).pipe(fs.createWriteStream(config.deck_path + file.name)); fs.createReadStream(filepath).pipe(fs.createWriteStream(config.deck_path + filename));
result.push({ result.push({ file: filename, status: "OK" });
file: file.name,
status: "OK",
});
} }
else { else {
result.push({ result.push({ file: filename, status: "卡组不合格" });
file: file.name,
status: "卡组不合格",
});
} }
} }
else { else {
result.push({ result.push({ file: filename, status: "不是卡组文件" });
file: file.name,
status: "不是卡组文件",
});
} }
} }
callback(null, result); 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