all repos — stealth-developers @ 72a01fcc0c16d5c82bfb11894f13ce9669dd349a

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.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 });
}