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

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

parents b9c3a5ad 3b813a9b
Pipeline #43211 failed with stages
in 103 minutes and 42 seconds
...@@ -165,29 +165,38 @@ const receiveDecks = async function ( ...@@ -165,29 +165,38 @@ const receiveDecks = async function (
callback: (err: Error | null, result: Array<{ file: string; status: string }>) => void callback: (err: Error | null, result: Array<{ file: string; status: string }>) => void
) { ) {
try { try {
// formidable parse() 返回的 files 通常是对象:{ fieldName: File | File[] }
// 老代码按数组 for..of 会直接抛:TypeError: files is not iterable
const fileList: any[] = Array.isArray(files)
? files
: files && typeof files === "object"
? Object.values(files).flatMap((v: any) => (Array.isArray(v) ? v : [v]))
: [];
const result: Array<{ file: string; status: string }> = []; const result: Array<{ file: string; status: string }> = [];
for (const file of files) {
if (file.name.endsWith(".ydk")) { for (const f of fileList) {
const deck = await readDeck(file.name, file.path); const filename: string = (f?.originalFilename ?? f?.name ?? "") as string;
const filepath: string = (f?.filepath ?? f?.path ?? "") as string;
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);
} catch (err) { } catch (err) {
callback(err as Error, []); callback(err as Error, []);
......
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