Fix R2 subdomain URL for tia bucket

This commit is contained in:
Manohar Gupta 2026-05-10 14:25:34 +05:30
parent cbc058acbe
commit 2bf37de50b

View file

@ -12,15 +12,20 @@ function getR2() {
throw new Error(`Missing R2 config`); throw new Error(`Missing R2 config`);
} }
// R2 uses path-style: https://<accountId>.r2.cloudflarestorage.com/<bucket> // Bucket is at subdomain: tia.<accountId>.r2.cloudflarestorage.com
// Or path: <accountId>.r2.cloudflarestorage.com/tia
const endpoint = bucket === "tia"
? `https://${bucket}.${accountId}.r2.cloudflarestorage.com`
: `https://${accountId}.r2.cloudflarestorage.com/${bucket}`;
return { return {
client: new S3Client({ client: new S3Client({
region: "auto", region: "auto",
endpoint: `https://${accountId}.r2.cloudflarestorage.com`, endpoint,
credentials: { accessKeyId, secretAccessKey: secretKey }, credentials: { accessKeyId, secretAccessKey: secretKey },
}), }),
bucket, bucket,
baseUrl: `https://${accountId}.r2.cloudflarestorage.com/${bucket}`, baseUrl: endpoint,
}; };
} }