feat: update file upload size handling to use dynamic max size #96
This commit is contained in:
+22
-18
@@ -11,7 +11,7 @@ import { useAuthStore, redirectToLogin } from "@/stores/auth-store";
|
|||||||
import { useEmailStore } from "@/stores/email-store";
|
import { useEmailStore } from "@/stores/email-store";
|
||||||
import { useFileStore } from "@/stores/file-store";
|
import { useFileStore } from "@/stores/file-store";
|
||||||
import { toast } from "@/stores/toast-store";
|
import { toast } from "@/stores/toast-store";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn, formatFileSize } from "@/lib/utils";
|
||||||
import { NavigationRail } from "@/components/layout/navigation-rail";
|
import { NavigationRail } from "@/components/layout/navigation-rail";
|
||||||
import { SidebarAppsModal } from "@/components/layout/sidebar-apps-modal";
|
import { SidebarAppsModal } from "@/components/layout/sidebar-apps-modal";
|
||||||
import { InlineAppView } from "@/components/layout/inline-app-view";
|
import { InlineAppView } from "@/components/layout/inline-app-view";
|
||||||
@@ -156,39 +156,43 @@ export default function FilesPage() {
|
|||||||
}
|
}
|
||||||
}, [createDirectory, t]);
|
}, [createDirectory, t]);
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 500 * 1024 * 1024; // 500 MB
|
const maxSizeUpload = client?.getMaxSizeUpload() || 0;
|
||||||
|
|
||||||
const handleUploadFiles = useCallback(async (files: File[]) => {
|
const handleUploadFiles = useCallback(async (files: File[]) => {
|
||||||
const oversized = files.filter(f => f.size > MAX_FILE_SIZE);
|
if (maxSizeUpload > 0) {
|
||||||
const valid = files.filter(f => f.size <= MAX_FILE_SIZE);
|
const oversized = files.filter(f => f.size > maxSizeUpload);
|
||||||
if (oversized.length > 0) {
|
files = files.filter(f => f.size <= maxSizeUpload);
|
||||||
toast.error(t("file_too_large", { name: oversized[0].name, max: "500 MB" }));
|
if (oversized.length > 0) {
|
||||||
|
toast.error(t("file_too_large", { name: oversized[0].name, max: formatFileSize(maxSizeUpload) }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (valid.length === 0) return;
|
if (files.length === 0) return;
|
||||||
try {
|
try {
|
||||||
await uploadFiles(valid);
|
await uploadFiles(files);
|
||||||
toast.success(t("upload_success", { count: valid.length }));
|
toast.success(t("upload_success", { count: files.length }));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to upload files:", err);
|
console.error("Failed to upload files:", err);
|
||||||
toast.error(t("upload_error"));
|
toast.error(t("upload_error"));
|
||||||
}
|
}
|
||||||
}, [uploadFiles, t]);
|
}, [uploadFiles, t, maxSizeUpload]);
|
||||||
|
|
||||||
const handleUploadFolder = useCallback(async (files: File[]) => {
|
const handleUploadFolder = useCallback(async (files: File[]) => {
|
||||||
const oversized = files.filter(f => f.size > MAX_FILE_SIZE);
|
if (maxSizeUpload > 0) {
|
||||||
const valid = files.filter(f => f.size <= MAX_FILE_SIZE);
|
const oversized = files.filter(f => f.size > maxSizeUpload);
|
||||||
if (oversized.length > 0) {
|
files = files.filter(f => f.size <= maxSizeUpload);
|
||||||
toast.error(t("file_too_large", { name: oversized[0].name, max: "500 MB" }));
|
if (oversized.length > 0) {
|
||||||
|
toast.error(t("file_too_large", { name: oversized[0].name, max: formatFileSize(maxSizeUpload) }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (valid.length === 0) return;
|
if (files.length === 0) return;
|
||||||
try {
|
try {
|
||||||
await uploadFolder(valid);
|
await uploadFolder(files);
|
||||||
toast.success(t("upload_success", { count: valid.length }));
|
toast.success(t("upload_success", { count: files.length }));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to upload folder:", err);
|
console.error("Failed to upload folder:", err);
|
||||||
toast.error(t("upload_error"));
|
toast.error(t("upload_error"));
|
||||||
}
|
}
|
||||||
}, [uploadFolder, t]);
|
}, [uploadFolder, t, maxSizeUpload]);
|
||||||
|
|
||||||
const handleDelete = useCallback(async (name: string) => {
|
const handleDelete = useCallback(async (name: string) => {
|
||||||
const confirmed = await confirmDialog({
|
const confirmed = await confirmDialog({
|
||||||
|
|||||||
@@ -181,8 +181,6 @@ function isPreviewable(name: string): boolean {
|
|||||||
return isImageFile(name) || isTextFile(name) || isPdfFile(name) || isAudioFile(name) || isVideoFile(name);
|
return isImageFile(name) || isTextFile(name) || isPdfFile(name) || isAudioFile(name) || isVideoFile(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 500 * 1024 * 1024; // 500 MB
|
|
||||||
|
|
||||||
function getFileIconByName(name: string, size: "sm" | "lg") {
|
function getFileIconByName(name: string, size: "sm" | "lg") {
|
||||||
const cls = size === "sm" ? "w-5 h-5" : "w-10 h-10";
|
const cls = size === "sm" ? "w-5 h-5" : "w-10 h-10";
|
||||||
if (isVectorFile(name)) return <PenTool className={`${cls} text-orange-500`} />;
|
if (isVectorFile(name)) return <PenTool className={`${cls} text-orange-500`} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user