s3: create the client instance from a function each time (so missing config doesn't crash it)
This commit is contained in:
parent
c20e0a0200
commit
94671b6a98
|
@ -3,8 +3,6 @@ import { IpfsHash, S3Client } from '@/deps.ts';
|
||||||
|
|
||||||
import type { Uploader } from './types.ts';
|
import type { Uploader } from './types.ts';
|
||||||
|
|
||||||
const s3 = new S3Client({ ...Conf.s3 });
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* S3-compatible uploader for AWS, Wasabi, DigitalOcean Spaces, and more.
|
* S3-compatible uploader for AWS, Wasabi, DigitalOcean Spaces, and more.
|
||||||
* Files are named by their IPFS CID and exposed at `/ipfs/<cid>`, letting it
|
* Files are named by their IPFS CID and exposed at `/ipfs/<cid>`, letting it
|
||||||
|
@ -14,7 +12,7 @@ const s3Uploader: Uploader = {
|
||||||
async upload(file) {
|
async upload(file) {
|
||||||
const cid = await IpfsHash.of(file.stream()) as string;
|
const cid = await IpfsHash.of(file.stream()) as string;
|
||||||
|
|
||||||
await s3.putObject(`ipfs/${cid}`, file.stream(), {
|
await client().putObject(`ipfs/${cid}`, file.stream(), {
|
||||||
metadata: {
|
metadata: {
|
||||||
'Content-Type': file.type,
|
'Content-Type': file.type,
|
||||||
'x-amz-acl': 'public-read',
|
'x-amz-acl': 'public-read',
|
||||||
|
@ -26,8 +24,13 @@ const s3Uploader: Uploader = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async delete(cid) {
|
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 };
|
export { s3Uploader };
|
||||||
|
|
Loading…
Reference in New Issue