Lazy load aws s3 client
This commit is contained in:
parent
fe992c0e17
commit
a1e97ce02d
@ -24,7 +24,7 @@ export const HAS_AWS_S3_STORAGE =
|
|||||||
S3_UPLOAD_ACCESS_KEY.length > 0 &&
|
S3_UPLOAD_ACCESS_KEY.length > 0 &&
|
||||||
S3_UPLOAD_SECRET_ACCESS_KEY.length > 0;
|
S3_UPLOAD_SECRET_ACCESS_KEY.length > 0;
|
||||||
|
|
||||||
const client = new S3Client({
|
const client = () => new S3Client({
|
||||||
region: S3_REGION,
|
region: S3_REGION,
|
||||||
credentials: {
|
credentials: {
|
||||||
// Fallback on upload credentials if admin credentials are not available
|
// Fallback on upload credentials if admin credentials are not available
|
||||||
@ -50,7 +50,7 @@ export const awsS3UploadFromClient = async (
|
|||||||
const Key = addRandomSuffix
|
const Key = addRandomSuffix
|
||||||
? `${fileName}-${generateNanoid()}.${extension}`
|
? `${fileName}-${generateNanoid()}.${extension}`
|
||||||
: `${fileName}.${extension}`;
|
: `${fileName}.${extension}`;
|
||||||
return client.send(new PutObjectCommand({
|
return client().send(new PutObjectCommand({
|
||||||
Bucket: S3_BUCKET,
|
Bucket: S3_BUCKET,
|
||||||
Key,
|
Key,
|
||||||
Body: file,
|
Body: file,
|
||||||
@ -69,7 +69,7 @@ export const awsS3Copy = async (
|
|||||||
const Key = addRandomSuffix
|
const Key = addRandomSuffix
|
||||||
? `${name}-${generateNanoid()}.${extension}`
|
? `${name}-${generateNanoid()}.${extension}`
|
||||||
: fileNameDestination;
|
: fileNameDestination;
|
||||||
return client.send(new CopyObjectCommand({
|
return client().send(new CopyObjectCommand({
|
||||||
Bucket: S3_BUCKET,
|
Bucket: S3_BUCKET,
|
||||||
CopySource: fileNameSource,
|
CopySource: fileNameSource,
|
||||||
Key,
|
Key,
|
||||||
@ -79,14 +79,14 @@ export const awsS3Copy = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const awsS3Delete = async (Key: string) => {
|
export const awsS3Delete = async (Key: string) => {
|
||||||
client.send(new DeleteObjectCommand({
|
client().send(new DeleteObjectCommand({
|
||||||
Bucket: S3_BUCKET,
|
Bucket: S3_BUCKET,
|
||||||
Key,
|
Key,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const awsS3List = async (Prefix: string) =>
|
export const awsS3List = async (Prefix: string) =>
|
||||||
client.send(new ListObjectsCommand({
|
client().send(new ListObjectsCommand({
|
||||||
Bucket: S3_BUCKET,
|
Bucket: S3_BUCKET,
|
||||||
Prefix,
|
Prefix,
|
||||||
}))
|
}))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user