- {selectedFile ? (
-
- ) : (
-
- )}
-
-
-
{selectedFile ? "" : "or drag and drop"}
+
- {selectedFile && (isPending || uploadProgress > 0) && (
-
-
-
- {isPending && uploadProgress < 100 ? `${uploadProgress}% uploading...` : state?.error ? 'Error' : uploadProgress === 100 && !isPending ? 'Complete' : `${uploadProgress}%`}
-
-
- )}
-
- {state?.error && state.message && !isPending && (
-
-
- Error
- {state.message}
-
+ {selectedFile && (isPending || uploadProgress > 0) && (
+
+
+
+ {isPending && uploadProgress < 100 ? `${uploadProgress}% uploading...` : state?.error ? 'Error' : uploadProgress === 100 && !isPending ? 'Complete' : `${uploadProgress}%`}
+
+
)}
-
-
+ {state?.error && state.message && !isPending && (
+
+
+ Error
+ {state.message}
+
+ )}
+
+
+
);
}
diff --git a/src/lib/actions/file.actions.ts b/src/lib/actions/file.actions.ts
index beae67f..1857f77 100644
--- a/src/lib/actions/file.actions.ts
+++ b/src/lib/actions/file.actions.ts
@@ -6,8 +6,9 @@ import { revalidatePath } from 'next/cache';
import { z } from 'zod';
import fs from 'node:fs';
import path from 'node:path';
+import { UPLOAD_LIMIT_MB } from '@/lib/config';
-const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB
+const MAX_FILE_SIZE = UPLOAD_LIMIT_MB * 1024 * 1024; // 500MB
// It's generally better to allow a wider range of types and let the application handle them,
// or use more robust server-side type checking if strict limitations are needed.
// For this prototype, we'll be more permissive on the client-side Zod schema for MIME types.
@@ -16,10 +17,10 @@ const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB
const fileSchema = z.object({
file: z
- .custom
((val) => val instanceof File, "Input is not a file")
- .refine((file) => file.size > 0, "File cannot be empty.")
- .refine((file) => file.size <= MAX_FILE_SIZE, `File size should be less than 50MB.`)
- // .refine((file) => ACCEPTED_FILE_TYPES_REGEX.test(file.type), "Unsupported file type.") // Relaxing this for broader prototype compatibility
+ .custom((val) => val instanceof File, "Input is not a file")
+ .refine((file) => file.size > 0, "File cannot be empty.")
+ .refine((file) => file.size <= MAX_FILE_SIZE, `File size should be less than ${UPLOAD_LIMIT_MB}MB.`)
+ // .refine((file) => ACCEPTED_FILE_TYPES_REGEX.test(file.type), "Unsupported file type.") // Relaxing this for broader prototype compatibility
});
@@ -29,7 +30,7 @@ export async function uploadFileAction(prevState: any, formData: FormData) {
if (!uploadedFile || uploadedFile.name === 'undefined' || uploadedFile.size === 0) { // Handle edge case where file might be 'undefined' string or empty
return { message: 'No file selected or file is empty.', error: true, file: null };
}
-
+
const validatedFields = fileSchema.safeParse({ file: uploadedFile });
if (!validatedFields.success) {
@@ -40,7 +41,7 @@ export async function uploadFileAction(prevState: any, formData: FormData) {
file: null,
};
}
-
+
try {
const newFileEntry = await addFile({
name: uploadedFile.name,
@@ -58,7 +59,7 @@ export async function uploadFileAction(prevState: any, formData: FormData) {
const fileBuffer = Buffer.from(await uploadedFile.arrayBuffer());
fs.writeFileSync(filePathInCdn, fileBuffer);
- revalidatePath('/browse');
+ revalidatePath('/browse');
revalidatePath(`/files/${newFileEntry.id}`);
revalidatePath(`/cdn/${newFileEntry.id}`);
@@ -67,7 +68,7 @@ export async function uploadFileAction(prevState: any, formData: FormData) {
console.error("Upload error:", e);
let errorMessage = 'Failed to upload file. Please try again.';
if (e instanceof Error) {
- errorMessage = `Failed to upload file: ${e.message}`;
+ errorMessage = `Failed to upload file: ${e.message}`;
}
return { message: errorMessage, error: true, file: null };
}
diff --git a/src/lib/config.ts b/src/lib/config.ts
new file mode 100644
index 0000000..91e6ecb
--- /dev/null
+++ b/src/lib/config.ts
@@ -0,0 +1 @@
+export const UPLOAD_LIMIT_MB = 500;
\ No newline at end of file