diff --git a/app/api/upload/route.ts b/app/api/upload/route.ts deleted file mode 100644 index 2f42d3aa0..000000000 --- a/app/api/upload/route.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { NextResponse } from "next/server"; -import uploadToArweave from "@/lib/arweave/uploadToArweave"; -import { getFetchableUrl } from "@/lib/arweave/gateway"; - -export async function POST(request: Request) { - try { - const formData = await request.formData(); - const file = formData.get("file") as File; - - if (!file) { - throw new Error("No file provided"); - } - - const fileBuffer = Buffer.from(await file.arrayBuffer()); - const fileSize = fileBuffer.length; - - const arweaveUrl = await uploadToArweave({ - base64Data: fileBuffer.toString("base64"), - mimeType: file.type || "application/octet-stream", - }); - - return NextResponse.json({ - success: true, - fileName: file.name, - fileType: file.type, - fileSize, - url: getFetchableUrl(arweaveUrl), - }); - } catch (error) { - console.error("Upload failed:", error); - return NextResponse.json( - { - success: false, - error: error instanceof Error ? error.message : "Unknown error", - }, - { status: 500 } - ); - } -} diff --git a/hooks/usePureFileAttachments.ts b/hooks/usePureFileAttachments.ts index 0515cfcdf..60228c39b 100644 --- a/hooks/usePureFileAttachments.ts +++ b/hooks/usePureFileAttachments.ts @@ -4,6 +4,7 @@ import { useVercelChatContext } from "@/providers/VercelChatProvider"; import { CHAT_INPUT_SUPPORTED_FILE } from "@/lib/chat/config"; import { isAllowedByExtension } from "@/lib/files/isAllowedByExtension"; import { getFileExtension } from "@/lib/files/getFileExtension"; +import { getClientApiBaseUrl } from "@/lib/api/getClientApiBaseUrl"; export function usePureFileAttachments() { const { setAttachments, addTextAttachment } = useVercelChatContext(); @@ -57,7 +58,7 @@ export function usePureFileAttachments() { const formData = new FormData(); formData.append("file", file); - const response = await fetch("/api/upload", { + const response = await fetch(`${getClientApiBaseUrl()}/api/upload`, { method: "POST", body: formData, }); @@ -83,8 +84,8 @@ export function usePureFileAttachments() { mediaType: data.fileType, url: data.url, } as FileUIPart) - : attachment - ) + : attachment, + ), ); // Revoke the temporary object URL to avoid memory leaks @@ -93,7 +94,7 @@ export function usePureFileAttachments() { console.error("Error uploading file:", error); // Remove the failed attachment setAttachments((prev: FileUIPart[]) => - prev.filter((a: FileUIPart) => a.url !== tempUrl) + prev.filter((a: FileUIPart) => a.url !== tempUrl), ); // Revoke the temporary object URL URL.revokeObjectURL(tempUrl); diff --git a/lib/arweave/uploadFile.tsx b/lib/arweave/uploadFile.tsx index f6ea2a5ab..da6897968 100644 --- a/lib/arweave/uploadFile.tsx +++ b/lib/arweave/uploadFile.tsx @@ -1,3 +1,5 @@ +import { getClientApiBaseUrl } from "@/lib/api/getClientApiBaseUrl"; + export type ArweaveUploadResponse = { id: string; uri: string; @@ -10,7 +12,7 @@ export const uploadFile = async ( const data = new FormData(); data.set("file", file); - const res = await fetch("/api/upload", { + const res = await fetch(`${getClientApiBaseUrl()}/api/upload`, { method: "POST", body: data, }); diff --git a/next.config.mjs b/next.config.mjs index c5387a5b5..2f2eab1a5 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -58,6 +58,12 @@ const nextConfig = { port: '', pathname: '/**', }, + { + protocol: 'https', + hostname: '*.supabase.co', + port: '', + pathname: '/storage/v1/object/public/**', + }, ], }, };