diff --git a/app/api/sandbox/upload/route.ts b/app/api/sandbox/upload/route.ts deleted file mode 100644 index 2fb52414b..000000000 --- a/app/api/sandbox/upload/route.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { handleUpload, type HandleUploadBody } from "@vercel/blob/client"; -import { NextResponse } from "next/server"; - -/** - * POST /api/sandbox/upload - * - * Handles client-side Vercel Blob uploads by generating presigned tokens. - * Auth is validated via clientPayload (the blob client controls its own - * request headers, so we validate the token passed in the payload). - * Files are temporarily stored in Vercel Blob, then the client passes - * the blob URLs to the API which commits them to GitHub and cleans up. - */ -export async function POST(request: Request): Promise { - try { - const body = (await request.json()) as HandleUploadBody; - - const jsonResponse = await handleUpload({ - body, - request, - onBeforeGenerateToken: async (_pathname, clientPayload) => { - const payload = clientPayload ? JSON.parse(clientPayload) : null; - if (!payload?.token) { - throw new Error("Authentication required"); - } - - return { - maximumSizeInBytes: 100 * 1024 * 1024, // 100MB - addRandomSuffix: true, - }; - }, - onUploadCompleted: async () => {}, - }); - - return NextResponse.json(jsonResponse); - } catch (error) { - return NextResponse.json( - { error: error instanceof Error ? error.message : "Upload failed" }, - { status: 400 }, - ); - } -} diff --git a/lib/sandboxes/uploadSandboxFiles.ts b/lib/sandboxes/uploadSandboxFiles.ts index dcfc685c6..df199d5af 100644 --- a/lib/sandboxes/uploadSandboxFiles.ts +++ b/lib/sandboxes/uploadSandboxFiles.ts @@ -40,8 +40,8 @@ export async function uploadSandboxFiles({ files.map(async (file) => { const blob = await upload(file.name, file, { access: "public", - handleUploadUrl: "/api/sandbox/upload", - clientPayload: JSON.stringify({ token: accessToken }), + handleUploadUrl: `${getClientApiBaseUrl()}/api/sandboxes/staged-file`, + headers: { Authorization: `Bearer ${accessToken}` }, }); return { url: blob.url, name: file.name }; }),