fix(web): upload toast always showed 0 files (live FileList read after input reset); snapshot before upload

This commit is contained in:
2026-09-08 16:22:12 +08:00
parent e5dacc0a77
commit 2721df8ea9
2 changed files with 7 additions and 3 deletions
+4 -3
View File
@@ -30,10 +30,11 @@ export default function AdminLibraries() {
});
async function onFiles(libId: number, list: FileList | null) {
if (!list?.length) return;
const files = Array.from(list ?? []); // FileList 是活引用,onChange 里 input.value="" 会清空它,必须先快照
if (!files.length) return;
try {
for (const f of Array.from(list)) await api.uploadBook(libId, f); // 串行,单个失败即止并报错
toast("ok", `已上传 ${list.length} 个文件,等待 scanner 收编`);
for (const f of files) await api.uploadBook(libId, f); // 串行,单个失败即止并报错
toast("ok", `已上传 ${files.length} 个文件,等待 scanner 收编`);
void qc.invalidateQueries({ queryKey: ["books"] });
setTimeout(() => void qc.invalidateQueries({ queryKey: ["books"] }), 5000);
} catch (e) {