Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/api/sandbox/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function POST(request: Request): Promise<NextResponse> {

return {
maximumSizeInBytes: 100 * 1024 * 1024, // 100MB
addRandomSuffix: true,
};
},
onUploadCompleted: async () => {},
Expand Down
23 changes: 21 additions & 2 deletions lib/sandboxes/uploadSandboxFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function uploadSandboxFiles({
path?: string;
message?: string;
}): Promise<{ uploaded: UploadedFile[]; errors?: string[] }> {
const blobFiles = await Promise.all(
const results = await Promise.allSettled(
files.map(async (file) => {
const blob = await upload(file.name, file, {
access: "public",
Expand All @@ -47,6 +47,23 @@ export async function uploadSandboxFiles({
}),
);

const blobFiles: { url: string; name: string }[] = [];
const blobErrors: string[] = [];

results.forEach((r, i) => {
if (r.status === "fulfilled") {
blobFiles.push(r.value);
} else {
blobErrors.push(`${files[i].name}: ${r.reason?.message || "Upload failed"}`);
}
});

if (blobFiles.length === 0) {
throw new Error(
blobErrors[0] || "Failed to upload files to temporary storage",
);
}

const response = await fetch(`${NEW_API_BASE_URL}/api/sandboxes/files`, {
method: "POST",
headers: {
Expand All @@ -66,8 +83,10 @@ export async function uploadSandboxFiles({
throw new Error(data.error || "Failed to upload files");
}

const allErrors = [...blobErrors, ...(data.errors || [])];

return {
uploaded: data.uploaded || [],
errors: data.errors,
...(allErrors.length > 0 && { errors: allErrors }),
};
}
Loading