fix: AWS configuration with AWS_S3_ACCELERATE_URL specified
This commit is contained in:
@@ -26,6 +26,7 @@ export default class S3Storage extends BaseStorage {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.client = new S3Client({
|
this.client = new S3Client({
|
||||||
|
bucketEndpoint: env.AWS_S3_ACCELERATE_URL ? true : false,
|
||||||
forcePathStyle: env.AWS_S3_FORCE_PATH_STYLE,
|
forcePathStyle: env.AWS_S3_FORCE_PATH_STYLE,
|
||||||
credentials: {
|
credentials: {
|
||||||
accessKeyId: env.AWS_ACCESS_KEY_ID || "",
|
accessKeyId: env.AWS_ACCESS_KEY_ID || "",
|
||||||
@@ -113,16 +114,11 @@ export default class S3Storage extends BaseStorage {
|
|||||||
key: string;
|
key: string;
|
||||||
acl?: string;
|
acl?: string;
|
||||||
}) => {
|
}) => {
|
||||||
invariant(
|
|
||||||
env.AWS_S3_UPLOAD_BUCKET_NAME,
|
|
||||||
"AWS_S3_UPLOAD_BUCKET_NAME is required"
|
|
||||||
);
|
|
||||||
|
|
||||||
const upload = new Upload({
|
const upload = new Upload({
|
||||||
client: this.client,
|
client: this.client,
|
||||||
params: {
|
params: {
|
||||||
ACL: acl as ObjectCannedACL,
|
ACL: acl as ObjectCannedACL,
|
||||||
Bucket: env.AWS_S3_UPLOAD_BUCKET_NAME,
|
Bucket: this.getBucket(),
|
||||||
Key: key,
|
Key: key,
|
||||||
ContentType: contentType,
|
ContentType: contentType,
|
||||||
ContentLength: contentLength,
|
ContentLength: contentLength,
|
||||||
@@ -137,14 +133,9 @@ export default class S3Storage extends BaseStorage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public async deleteFile(key: string) {
|
public async deleteFile(key: string) {
|
||||||
invariant(
|
|
||||||
env.AWS_S3_UPLOAD_BUCKET_NAME,
|
|
||||||
"AWS_S3_UPLOAD_BUCKET_NAME is required"
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.client.send(
|
await this.client.send(
|
||||||
new DeleteObjectCommand({
|
new DeleteObjectCommand({
|
||||||
Bucket: env.AWS_S3_UPLOAD_BUCKET_NAME,
|
Bucket: this.getBucket(),
|
||||||
Key: key,
|
Key: key,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -156,7 +147,7 @@ export default class S3Storage extends BaseStorage {
|
|||||||
) => {
|
) => {
|
||||||
const isDocker = env.AWS_S3_UPLOAD_BUCKET_URL.match(/http:\/\/s3:/);
|
const isDocker = env.AWS_S3_UPLOAD_BUCKET_URL.match(/http:\/\/s3:/);
|
||||||
const params = {
|
const params = {
|
||||||
Bucket: env.AWS_S3_UPLOAD_BUCKET_NAME,
|
Bucket: this.getBucket(),
|
||||||
Key: key,
|
Key: key,
|
||||||
Expires: expiresIn,
|
Expires: expiresIn,
|
||||||
};
|
};
|
||||||
@@ -211,15 +202,10 @@ export default class S3Storage extends BaseStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getFileStream(key: string): Promise<NodeJS.ReadableStream | null> {
|
public getFileStream(key: string): Promise<NodeJS.ReadableStream | null> {
|
||||||
invariant(
|
|
||||||
env.AWS_S3_UPLOAD_BUCKET_NAME,
|
|
||||||
"AWS_S3_UPLOAD_BUCKET_NAME is required"
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.client
|
return this.client
|
||||||
.send(
|
.send(
|
||||||
new GetObjectCommand({
|
new GetObjectCommand({
|
||||||
Bucket: env.AWS_S3_UPLOAD_BUCKET_NAME,
|
Bucket: this.getBucket(),
|
||||||
Key: key,
|
Key: key,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -251,4 +237,8 @@ export default class S3Storage extends BaseStorage {
|
|||||||
|
|
||||||
return env.AWS_S3_UPLOAD_BUCKET_URL;
|
return env.AWS_S3_UPLOAD_BUCKET_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getBucket() {
|
||||||
|
return env.AWS_S3_ACCELERATE_URL || env.AWS_S3_UPLOAD_BUCKET_NAME || "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user