import { CopyObjectCommand, DeleteObjectCommand, S3Client, } from "@aws-sdk/client-s3"; import { getConfig } from "../config.ts"; export class AwsContext { readonly region = "ap-southeast-1"; accessKeyId = getConfig().getValue("awsAccessKeyId"); secretAccessKey = getConfig().getValue("awsSecretAccessKey"); getCredentials() { const { accessKeyId, secretAccessKey } = this; return Promise.resolve({ accessKeyId, secretAccessKey }); } readonly credentials = this.getCredentials.bind(this); } export async function s3MoveObject( client: S3Client, bucket: string, path: string, newPath: string, ): Promise { const copyCommand = new CopyObjectCommand({ Bucket: bucket, Key: newPath, CopySource: path, }); await client.send(copyCommand); const deleteCommand = new DeleteObjectCommand({ Bucket: bucket, Key: path, }); await client.send(deleteCommand); }