diff --git a/app/(app)/files/actions.ts b/app/(app)/files/actions.ts index 2d4a4f9..2399cb6 100644 --- a/app/(app)/files/actions.ts +++ b/app/(app)/files/actions.ts @@ -12,11 +12,17 @@ import path from "path" export async function uploadFilesAction(formData: FormData): Promise> { const user = await getCurrentUser() - const files = formData.getAll("files") + const files = formData.getAll("files") as File[] // Make sure upload dir exists const userUploadsDirectory = await getUserUploadsDirectory(user) + // Check limits + const totalFileSize = files.reduce((acc, file) => acc + file.size, 0) + if (!isEnoughStorageToUploadFile(user, totalFileSize)) { + return { success: false, error: `Insufficient storage to upload these files` } + } + // Process each file const uploadedFiles = await Promise.all( files.map(async (file) => { @@ -24,10 +30,6 @@ export async function uploadFilesAction(formData: FormData): Promise