src/utils/s3.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import config from "@/config";
import { S3Client } from "bun";
export const s3 = new S3Client({
accessKeyId: config.data.s3.accessKeyId,
secretAccessKey: config.data.s3.secretAccessKey,
bucket: config.data.s3.bucket,
endpoint: config.data.s3.endpoint,
region: config.data.s3.region,
});
export function getPublicUrl(key: string) {
if (config.data.s3.publicUrl) {
return `${config.data.s3.publicUrl}/${key}`;
}
return s3.file(key).presign({ expiresIn: 3600 });
}
|