From 94671b6a98568a85147df7749bfa599231705717 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 11 Sep 2023 14:41:30 -0500 Subject: [PATCH] s3: create the client instance from a function each time (so missing config doesn't crash it) --- src/uploaders/s3.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/uploaders/s3.ts b/src/uploaders/s3.ts index 9242bee..378b279 100644 --- a/src/uploaders/s3.ts +++ b/src/uploaders/s3.ts @@ -3,8 +3,6 @@ import { IpfsHash, S3Client } from '@/deps.ts'; import type { Uploader } from './types.ts'; -const s3 = new S3Client({ ...Conf.s3 }); - /** * S3-compatible uploader for AWS, Wasabi, DigitalOcean Spaces, and more. * Files are named by their IPFS CID and exposed at `/ipfs/`, letting it @@ -14,7 +12,7 @@ const s3Uploader: Uploader = { async upload(file) { const cid = await IpfsHash.of(file.stream()) as string; - await s3.putObject(`ipfs/${cid}`, file.stream(), { + await client().putObject(`ipfs/${cid}`, file.stream(), { metadata: { 'Content-Type': file.type, 'x-amz-acl': 'public-read', @@ -26,8 +24,13 @@ const s3Uploader: Uploader = { }; }, async delete(cid) { - await s3.deleteObject(`ipfs/${cid}`); + await client().deleteObject(`ipfs/${cid}`); }, }; +/** Build S3 client from config. */ +function client() { + return new S3Client({ ...Conf.s3 }); +} + export { s3Uploader };