error handling + file size
This commit is contained in:
@@ -3,6 +3,9 @@ import { prisma } from "@/lib/db";
|
|||||||
import { getSessionUser } from "@/lib/auth";
|
import { getSessionUser } from "@/lib/auth";
|
||||||
import { uploadToR2 } from "@/lib/r2";
|
import { uploadToR2 } from "@/lib/r2";
|
||||||
|
|
||||||
|
// Route segment config for App Router - extend timeout for large uploads
|
||||||
|
export const maxDuration = 300; // 5 minutes
|
||||||
|
|
||||||
const MAX_UPLOAD_SIZE = 10 * 1024 * 1024 * 1024; // 10GB in bytes
|
const MAX_UPLOAD_SIZE = 10 * 1024 * 1024 * 1024; // 10GB in bytes
|
||||||
|
|
||||||
function serializeFile(file: Awaited<ReturnType<typeof prisma.file.create>>) {
|
function serializeFile(file: Awaited<ReturnType<typeof prisma.file.create>>) {
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ export async function middleware(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: ["/dashboard/:path*", "/api/files/:path*"],
|
matcher: [
|
||||||
|
"/dashboard/:path*",
|
||||||
|
// Match all /api/files routes EXCEPT /api/files/upload (which handles large bodies)
|
||||||
|
"/api/files/list",
|
||||||
|
"/api/files/delete-all",
|
||||||
|
"/api/files/:id/download",
|
||||||
|
"/api/files/:id/delete",
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ const nextConfig: NextConfig = {
|
|||||||
// Disable server/dev sourcemaps to avoid Windows source map parse warnings
|
// Disable server/dev sourcemaps to avoid Windows source map parse warnings
|
||||||
productionBrowserSourceMaps: false,
|
productionBrowserSourceMaps: false,
|
||||||
|
|
||||||
|
// Allow large file uploads (up to 10GB)
|
||||||
|
experimental: {
|
||||||
|
serverActions: {
|
||||||
|
bodySizeLimit: "10gb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
webpack: (config, { dev, isServer }) => {
|
webpack: (config, { dev, isServer }) => {
|
||||||
if (dev && isServer) {
|
if (dev && isServer) {
|
||||||
config.devtool = false;
|
config.devtool = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user