Merge pull request #1142 from dg-i/configurable-s3-endpoint

Make AWS S3 endpoint configurable
This commit is contained in:
Raccoon 2019-04-15 13:37:33 +08:00 committed by GitHub
commit d127b8ef7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -40,7 +40,8 @@ module.exports = {
s3: { s3: {
accessKeyId: process.env.CMD_S3_ACCESS_KEY_ID, accessKeyId: process.env.CMD_S3_ACCESS_KEY_ID,
secretAccessKey: process.env.CMD_S3_SECRET_ACCESS_KEY, secretAccessKey: process.env.CMD_S3_SECRET_ACCESS_KEY,
region: process.env.CMD_S3_REGION region: process.env.CMD_S3_REGION,
endpoint: process.env.CMD_S3_ENDPOINT
}, },
minio: { minio: {
accessKey: process.env.CMD_MINIO_ACCESS_KEY, accessKey: process.env.CMD_MINIO_ACCESS_KEY,

View File

@ -42,7 +42,9 @@ exports.uploadImage = function (imagePath, callback) {
} }
let s3Endpoint = 's3.amazonaws.com' let s3Endpoint = 's3.amazonaws.com'
if (config.s3.region && config.s3.region !== 'us-east-1') { if (config.s3.endpoint) {
s3Endpoint = config.s3.endpoint
} else if (config.s3.region && config.s3.region !== 'us-east-1') {
s3Endpoint = `s3-${config.s3.region}.amazonaws.com` s3Endpoint = `s3-${config.s3.region}.amazonaws.com`
} }
callback(null, `https://${s3Endpoint}/${config.s3bucket}/${params.Key}`) callback(null, `https://${s3Endpoint}/${config.s3bucket}/${params.Key}`)