feat: enhance API configuration and file handling for improved performance

- Added experimental server actions and increased body size limits in next.config.ts to support larger payloads.
- Updated the download route to directly use the response body from the API, optimizing data handling.
- Modified the upload route to utilize the request body directly and adjusted content length handling for better compatibility.
This commit is contained in:
Daniel Luiz Alves
2025-07-03 00:23:11 -03:00
parent 3551732aa3
commit d5918c3088
3 changed files with 16 additions and 6 deletions

View File

@@ -16,6 +16,17 @@ const nextConfig: NextConfig = {
],
},
serverExternalPackages: [],
experimental: {
serverActions: {
bodySizeLimit: "1pb",
},
},
api: {
bodyParser: {
sizeLimit: "1pb",
},
responseLimit: false,
},
};
const withNextIntl = createNextIntlPlugin();

View File

@@ -18,8 +18,7 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ toke
const contentDisposition = apiRes.headers.get("Content-Disposition");
const contentLength = apiRes.headers.get("Content-Length");
const resBody = await apiRes.arrayBuffer();
const res = new NextResponse(resBody, {
const res = new NextResponse(apiRes.body, {
status: apiRes.status,
headers: {
"Content-Type": contentType,

View File

@@ -8,7 +8,6 @@ const API_BASE_URL = process.env.API_BASE_URL || "http://localhost:3333";
export async function PUT(req: NextRequest, { params }: { params: Promise<{ token: string }> }) {
const { token } = await params;
const cookieHeader = req.headers.get("cookie");
const body = await req.arrayBuffer();
const url = `${API_BASE_URL}/filesystem/upload/${token}`;
const apiRes = await fetch(url, {
@@ -16,10 +15,11 @@ export async function PUT(req: NextRequest, { params }: { params: Promise<{ toke
headers: {
cookie: cookieHeader || "",
"Content-Type": req.headers.get("Content-Type") || "application/octet-stream",
"Content-Length": req.headers.get("Content-Length") || body.byteLength.toString(),
"Content-Length": req.headers.get("Content-Length") || "0",
},
body: body,
});
body: req.body,
duplex: "half",
} as RequestInit);
const contentType = apiRes.headers.get("Content-Type") || "application/json";