mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
fix: storage error is not shown
This commit is contained in:
@@ -12,11 +12,17 @@ import path from "path"
|
|||||||
|
|
||||||
export async function uploadFilesAction(formData: FormData): Promise<ActionState<null>> {
|
export async function uploadFilesAction(formData: FormData): Promise<ActionState<null>> {
|
||||||
const user = await getCurrentUser()
|
const user = await getCurrentUser()
|
||||||
const files = formData.getAll("files")
|
const files = formData.getAll("files") as File[]
|
||||||
|
|
||||||
// Make sure upload dir exists
|
// Make sure upload dir exists
|
||||||
const userUploadsDirectory = await getUserUploadsDirectory(user)
|
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
|
// Process each file
|
||||||
const uploadedFiles = await Promise.all(
|
const uploadedFiles = await Promise.all(
|
||||||
files.map(async (file) => {
|
files.map(async (file) => {
|
||||||
@@ -24,10 +30,6 @@ export async function uploadFilesAction(formData: FormData): Promise<ActionState
|
|||||||
return { success: false, error: "Invalid file" }
|
return { success: false, error: "Invalid file" }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEnoughStorageToUploadFile(user, file.size)) {
|
|
||||||
return { success: false, error: `Insufficient storage to upload this file: ${file.name}` }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save file to filesystem
|
// Save file to filesystem
|
||||||
const fileUuid = randomUUID()
|
const fileUuid = randomUUID()
|
||||||
const relativeFilePath = await unsortedFilePath(fileUuid, file.name)
|
const relativeFilePath = await unsortedFilePath(fileUuid, file.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user