Use env vars for R2 (remove hardcoded creds)
This commit is contained in:
parent
070293498b
commit
c58f64552d
1 changed files with 11 additions and 5 deletions
|
|
@ -3,12 +3,18 @@ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
const R2 = {
|
const R2 = {
|
||||||
accountId: "e71f22a2f8614fb3ba6d9b28a264d8ce",
|
accountId: process.env.R2_ACCOUNT_ID!,
|
||||||
accessKeyId: "6606d525c8e647d94e051b6d6565803b",
|
accessKeyId: process.env.R2_ACCESS_KEY_ID!,
|
||||||
secretKey: "244fcc44041f452241cbc68374cd7a6ca651cb71f361bc36cc932407bbe37863",
|
secretKey: process.env.R2_SECRET_ACCESS_KEY!,
|
||||||
bucket: "tia",
|
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({
|
const client = new S3Client({
|
||||||
region: "auto",
|
region: "auto",
|
||||||
endpoint: `https://${R2.accountId}.r2.cloudflarestorage.com`,
|
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() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue