fix: validate import size
This commit is contained in:
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 { getFileTaskById } from "@/features/file-task/services/file-task-service.ts";
|
||||||
import { queryClient } from "@/main.tsx";
|
import { queryClient } from "@/main.tsx";
|
||||||
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
|
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
|
||||||
|
import bytes from "bytes";
|
||||||
|
|
||||||
interface PageImportModalProps {
|
interface PageImportModalProps {
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
|
|
@ -100,6 +101,17 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||||
return;
|
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 {
|
try {
|
||||||
onClose();
|
onClose();
|
||||||
|
|
||||||
|
|
@ -230,11 +242,26 @@ function ImportFormatSelection({ spaceId, onClose }: ImportFormatSelection) {
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}, [fileTaskId]);
|
}, [fileTaskId]);
|
||||||
|
|
||||||
|
const maxSingleFileSize = bytes("20mb");
|
||||||
|
|
||||||
const handleFileUpload = async (selectedFiles: File[]) => {
|
const handleFileUpload = async (selectedFiles: File[]) => {
|
||||||
if (!selectedFiles) {
|
if (!selectedFiles) {
|
||||||
return;
|
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();
|
onClose();
|
||||||
|
|
||||||
const alert = notifications.show({
|
const alert = notifications.show({
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ export class ImportController {
|
||||||
) {
|
) {
|
||||||
const validFileExtensions = ['.md', '.html', '.docx'];
|
const validFileExtensions = ['.md', '.html', '.docx'];
|
||||||
|
|
||||||
const maxFileSize = bytes('10mb');
|
const maxFileSize = bytes('20mb');
|
||||||
|
|
||||||
let file = null;
|
let file = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue