diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-04-10 15:12:46 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-05 21:07:37 +0800 |
commit | 750aaddc978156d370ab10737d6b9e4449b7eb7e (patch) | |
tree | d14d4ac7ebe02aa6cada75d72b4ec6eddc8b6d7b /deno/mail-relay/aws/context.ts | |
parent | 04c86d8cec22d1c0883eb240453c160ea12da162 (diff) | |
download | crupest-750aaddc978156d370ab10737d6b9e4449b7eb7e.tar.gz crupest-750aaddc978156d370ab10737d6b9e4449b7eb7e.tar.bz2 crupest-750aaddc978156d370ab10737d6b9e4449b7eb7e.zip |
feat(mail-server): done aws message id mapping.
Diffstat (limited to 'deno/mail-relay/aws/context.ts')
-rw-r--r-- | deno/mail-relay/aws/context.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/deno/mail-relay/aws/context.ts b/deno/mail-relay/aws/context.ts new file mode 100644 index 0000000..b1e0336 --- /dev/null +++ b/deno/mail-relay/aws/context.ts @@ -0,0 +1,41 @@ +import { + CopyObjectCommand, + DeleteObjectCommand, + S3Client, +} from "@aws-sdk/client-s3"; +import { FetchHttpHandler } from "@smithy/fetch-http-handler"; + +import config from "../config.ts"; + +export class AwsContext { + readonly credentials = () => + Promise.resolve({ + accessKeyId: config.get("awsUser"), + secretAccessKey: config.get("awsPassword"), + }); + readonly requestHandler = new FetchHttpHandler(); + + get region() { + return config.get("awsRegion"); + } +} + +export async function s3MoveObject( + client: S3Client, + bucket: string, + path: string, + newPath: string, +): Promise<void> { + const copyCommand = new CopyObjectCommand({ + Bucket: bucket, + Key: newPath, + CopySource: `${bucket}/${path}`, + }); + await client.send(copyCommand); + + const deleteCommand = new DeleteObjectCommand({ + Bucket: bucket, + Key: path, + }); + await client.send(deleteCommand); +} |