fix: validate import size

This commit is contained in:
Philipinho
2026-03-03 20:00:05 +00:00
parent f12bfc1ff7
commit 057360c6be
2 changed files with 28 additions and 1 deletions
@@ -34,6 +34,7 @@ import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
import { getFileTaskById } from "@/features/file-task/services/file-task-service.ts";
import { queryClient } from "@/main.tsx";
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
import bytes from "bytes";
interface PageImportModalProps {
spaceId: string;
@@ -100,6 +101,17 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
return;
}
const maxSize = getFileImportSizeLimit();
if (selectedFile.size > maxSize) {
notifications.show({
color: "red",
message: t("File exceeds the {{limit}} import limit", {
limit: formatBytes(maxSize),
}),
});
return;
}
try {
onClose();
@@ -230,11 +242,26 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
}, 3000);
}, [fileTaskId]);
const maxSingleFileSize = bytes("20mb");
const handleFileUpload = async (selectedFiles: File[]) => {
if (!selectedFiles) {
return;
}
const oversizedFiles = selectedFiles.filter(
(f) => f.size > maxSingleFileSize,
);
if (oversizedFiles.length > 0) {
notifications.show({
color: "red",
message: t("File exceeds the {{limit}} import limit", {
limit: formatBytes(maxSingleFileSize),
}),
});
return;
}
onClose();
const alert = notifications.show({
@@ -53,7 +53,7 @@ export class ImportController {
) {
const validFileExtensions = ['.md', '.html', '.docx'];
const maxFileSize = bytes('10mb');
const maxFileSize = bytes('20mb');
let file = null;
try {