import { PutObjectCommand, GetObjectCommand, DeleteObjectCommand, HeadObjectCommand, } from "@aws-sdk/client-s3"; import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; import { r2, R2_BUCKET_NAME } from "./r2"; export async function uploadR2Artifact(params: { key: string; body: Buffer | string; contentType: string; }) { await r2.send( new PutObjectCommand({ Bucket: R2_BUCKET_NAME, Key: params.key, Body: params.body, ContentType: params.contentType, }) ); return params.key; } export async function getR2ArtifactDownloadUrl(key: string) { return await getSignedUrl( r2, new GetObjectCommand({ Bucket: R2_BUCKET_NAME, Key: key, }), { expiresIn: 60 * 10, } ); } export async function getR2ArtifactUploadUrl(params: { key: string; contentType: string; }) { return await getSignedUrl( r2, new PutObjectCommand({ Bucket: R2_BUCKET_NAME, Key: params.key, ContentType: params.contentType, }), { expiresIn: 60 * 10, } ); } export async function deleteR2Artifact(key: string) { await r2.send( new DeleteObjectCommand({ Bucket: R2_BUCKET_NAME, Key: key, }) ); } export async function r2ArtifactExists(key: string) { try { await r2.send( new HeadObjectCommand({ Bucket: R2_BUCKET_NAME, Key: key, }) ); return true; } catch { return false; } }