feat(media): add reference-aware S3 image delivery
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import "server-only";
|
||||
|
||||
import { S3Client } from "bun";
|
||||
|
||||
let client: S3Client | undefined;
|
||||
|
||||
function required(name: string): string {
|
||||
const value = process.env[name];
|
||||
if (!value) throw new Error(`${name} is required for media storage.`);
|
||||
return value;
|
||||
}
|
||||
|
||||
export function getMediaStorage(): S3Client {
|
||||
if (!client) {
|
||||
client = new S3Client({
|
||||
accessKeyId: required("S3_ACCESS_KEY_ID"),
|
||||
secretAccessKey: required("S3_SECRET_ACCESS_KEY"),
|
||||
bucket: required("S3_BUCKET"),
|
||||
endpoint: required("S3_ENDPOINT"),
|
||||
region: process.env.S3_REGION || "auto",
|
||||
virtualHostedStyle: process.env.S3_VIRTUAL_HOSTED_STYLE === "true",
|
||||
});
|
||||
}
|
||||
return client;
|
||||
}
|
||||
Reference in New Issue
Block a user