mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix: validate import size
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user