import config from "@stealth-developers/config"; import { S3Client } from "bun"; export const s3 = new S3Client({ accessKeyId: config.s3.accessKeyId, secretAccessKey: config.s3.secretAccessKey, bucket: config.s3.bucket, endpoint: config.s3.endpoint, region: config.s3.region, }); export function getPublicUrl(key: string) { if (config.s3.publicUrl) { return `${config.s3.publicUrl}/${key}`; } return s3.file(key).presign({ expiresIn: 3600 }); } export type PresignOptions = { expiresIn?: number; method?: "GET" | "PUT" | "POST" | "DELETE"; headers?: Record; }; export function getPresignedUrl(key: string, opts: PresignOptions = {}) { const { expiresIn = 3600, method, headers } = opts; const presignOpts: any = { expiresIn }; if (method) presignOpts.method = method; if (headers) presignOpts.headers = headers; return s3.file(key).presign(presignOpts); }