From c58f64552d6ac3ff58e4b5f98e05e4613b3d7e3c Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 10 May 2026 15:18:49 +0530 Subject: [PATCH] Use env vars for R2 (remove hardcoded creds) --- src/app/api/upload/route.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 200ee75..65e5b45 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -3,12 +3,18 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; import { NextRequest, NextResponse } from "next/server"; const R2 = { - accountId: "e71f22a2f8614fb3ba6d9b28a264d8ce", - accessKeyId: "6606d525c8e647d94e051b6d6565803b", - secretKey: "244fcc44041f452241cbc68374cd7a6ca651cb71f361bc36cc932407bbe37863", - bucket: "tia", + accountId: process.env.R2_ACCOUNT_ID!, + accessKeyId: process.env.R2_ACCESS_KEY_ID!, + secretKey: process.env.R2_SECRET_ACCESS_KEY!, + bucket: process.env.R2_BUCKET_NAME!, + // Public URL from bucket settings - enable "Public Development URL" + publicUrl: process.env.R2_PUBLIC_URL, }; +if (!R2.accountId || !R2.accessKeyId || !R2.secretKey || !R2.bucket) { + throw new Error("Missing R2 environment variables"); +} + const client = new S3Client({ region: "auto", endpoint: `https://${R2.accountId}.r2.cloudflarestorage.com`, @@ -18,7 +24,7 @@ const client = new S3Client({ }, }); -const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev`; +const baseUrl = R2.publicUrl || `https://pub-${R2.accountId}.r2.dev`; export async function GET() { try {