diff --git a/setup.js b/setup.js index 572e0c1..b82df28 100755 --- a/setup.js +++ b/setup.js @@ -16,16 +16,20 @@ const config = { s3enabled: false, s3endpoint: 'sfo3.digitaloceanspaces.com', s3bucket: 'bucket-name', + s3bucketEndpoint: false, s3accessKey: 'accessKey', s3secretKey: 'secretKey', }; // If directly called on the command line, run setup script if (require.main === module) { - const { path, log } = require('./utils'); + const TLog = require('@tycrek/log'); + const path = (...paths) => require('path').join(__dirname, ...paths); const fs = require('fs-extra'); const prompt = require('prompt'); + const log = new TLog({ timestamp: { enabled: false } }); + // Override default config with existing config to allow migrating configs try { const existingConfig = require('./config.json'); @@ -140,6 +144,12 @@ if (require.main === module) { default: config.s3bucket, required: false }, + s3bucketEndpoint: { + description: 'Whether the provided endpoint is a bucket (true) or a bucket subdomain (false)', + type: 'boolean', + default: config.s3bucketEndpoint, + required: false + }, s3accessKey: { description: 'Access key for the specified S3 API', type: 'string', diff --git a/storage.js b/storage.js index 0e6b227..7828439 100644 --- a/storage.js +++ b/storage.js @@ -8,13 +8,14 @@ const Thumbnail = require('./thumbnails'); const Vibrant = require('./vibrant'); const Hash = require('./hash'); const { getDatedDirname, sanitize, generateId, formatBytes, log } = require('./utils'); -const { s3enabled, s3endpoint, s3bucket, s3accessKey, s3secretKey, saveAsOriginal, maxUploadSize, mediaStrict } = require('./config.json'); +const { s3enabled, s3endpoint, s3bucket, s3bucketEndpoint, s3accessKey, s3secretKey, saveAsOriginal, maxUploadSize, mediaStrict } = require('./config.json'); const { CODE_UNSUPPORTED_MEDIA_TYPE } = require('./MagicNumbers.json'); const ID_GEN_LENGTH = 32; const ALLOWED_MIMETYPES = /(image)|(video)|(audio)\//; const s3 = new aws.S3({ + s3BucketEndpoint: s3bucketEndpoint, endpoint: new aws.Endpoint(s3endpoint), credentials: new aws.Credentials({ accessKeyId: s3accessKey, secretAccessKey: s3secretKey }) });