fix(est): reject oversized attachments early

This commit is contained in:
2026-11-07 11:23:39 +09:00
parent d2a8889475
commit 20ef5a6a7f
6 changed files with 45 additions and 5 deletions
+23 -2
View File
@@ -20,6 +20,24 @@ const EstAttachments = (() => {
reader.readAsDataURL(file);
});
}
function requiredBytes(project, files) {
const metadata = files.map((file) => ({
id: "0".repeat(36),
name: file.name,
type: file.type || "",
size: file.size,
data: "",
}));
const candidate = {
...project,
id: project.id || "0".repeat(24),
attachments: [...(project.attachments || []), ...metadata],
};
return (
new Blob([JSON.stringify(candidate)]).size +
files.reduce((sum, file) => sum + 4 * Math.ceil(file.size / 3), 0)
);
}
function install() {
document.addEventListener("change", async (event) => {
const input = event.target;
@@ -28,7 +46,10 @@ const EstAttachments = (() => {
key = state.documentKey,
revision = state.revision;
try {
const files = await Promise.all([...input.files].map(read));
const selected = [...input.files];
if (requiredBytes(state.project, selected) > 256 * 1024 * 1024)
throw Error("첨부파일을 포함한 작업이 저장 한도 256MB를 초과합니다.");
const files = await Promise.all(selected.map(read));
if (key !== state.documentKey || revision !== state.revision)
throw Error("작업이 변경되었습니다. 첨부파일을 다시 추가하세요.");
EstApp.change(() => (state.project.attachments ||= []).push(...files), false);
@@ -57,5 +78,5 @@ const EstAttachments = (() => {
}
});
}
return { render, install };
return { render, install, requiredBytes };
})();