Spaces:
Runtime error
Runtime error
| import { | |
| PutObjectCommand, | |
| GetObjectCommand, | |
| DeleteObjectCommand, | |
| HeadObjectCommand, | |
| } from "@aws-sdk/client-s3"; | |
| import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; | |
| import { s3, S3_BUCKET_NAME } from "./s3"; | |
| export async function uploadArtifact(params: { | |
| key: string; | |
| body: Buffer | string; | |
| contentType: string; | |
| }) { | |
| await s3.send( | |
| new PutObjectCommand({ | |
| Bucket: S3_BUCKET_NAME, | |
| Key: params.key, | |
| Body: params.body, | |
| ContentType: params.contentType, | |
| }) | |
| ); | |
| return params.key; | |
| } | |
| export async function getArtifactDownloadUrl(key: string) { | |
| return await getSignedUrl( | |
| s3, | |
| new GetObjectCommand({ | |
| Bucket: S3_BUCKET_NAME, | |
| Key: key, | |
| }), | |
| { | |
| expiresIn: 60 * 10, | |
| } | |
| ); | |
| } | |
| export async function getArtifactUploadUrl(params: { | |
| key: string; | |
| contentType: string; | |
| }) { | |
| return await getSignedUrl( | |
| s3, | |
| new PutObjectCommand({ | |
| Bucket: S3_BUCKET_NAME, | |
| Key: params.key, | |
| ContentType: params.contentType, | |
| }), | |
| { | |
| expiresIn: 60 * 10, | |
| } | |
| ); | |
| } | |
| export async function deleteArtifact(key: string) { | |
| await s3.send( | |
| new DeleteObjectCommand({ | |
| Bucket: S3_BUCKET_NAME, | |
| Key: key, | |
| }) | |
| ); | |
| } | |
| export async function artifactExists(key: string) { | |
| try { | |
| await s3.send( | |
| new HeadObjectCommand({ | |
| Bucket: S3_BUCKET_NAME, | |
| Key: key, | |
| }) | |
| ); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } |