From 8a89498591d13ad0b2c3c28c0553bbee4e616e74 Mon Sep 17 00:00:00 2001 From: mei23 Date: Thu, 26 Jul 2018 17:29:05 +0900 Subject: [PATCH 1/2] Add config.drive.baseUrl --- src/config/types.ts | 1 + src/services/drive/add-file.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/types.ts b/src/config/types.ts index b55465082..a3d55e284 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -53,6 +53,7 @@ export type Source = { storage: string; bucket?: string; prefix?: string; + baseUrl?: string; config?: any; }; diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index dbb1224cd..48f238819 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -25,6 +25,8 @@ async function save(readable: stream.Readable, name: string, type: string, hash: const minio = new Minio.Client(config.drive.config); const id = uuid.v4(); const obj = `${config.drive.prefix}/${id}`; + const baseUrl = config.drive.baseUrl + || `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }`; await minio.putObject(config.drive.bucket, obj, readable, size, { 'Content-Type': type, 'Cache-Control': 'max-age=31536000, immutable' }); Object.assign(metadata, { @@ -33,7 +35,7 @@ async function save(readable: stream.Readable, name: string, type: string, hash: storageProps: { id: id }, - url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }` + url: `${ baseUrl }/${ obj }` }); const file = await DriveFile.insert({ From 3d7680de3d78ff1d65f1271f041feb7dc6c67eef Mon Sep 17 00:00:00 2001 From: mei23 Date: Thu, 26 Jul 2018 17:42:08 +0900 Subject: [PATCH 2/2] Add S3 examples --- .config/example.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.config/example.yml b/.config/example.yml index e787274fd..05dc43c44 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -68,6 +68,29 @@ drive: # accessKey: # secretKey: + # S3 example + # storage: 'minio' + # bucket: bucket-name + # prefix: files + # config: + # endPoint: s3-us-west-2.amazonaws.com + # region: us-west-2 + # secure: true + # accessKey: XXX + # secretKey: YYY + + # S3 example (with CDN, custom domain) + # storage: 'minio' + # bucket: drive.example.com + # prefix: files + # baseUrl: https://drive.example.com + # config: + # endPoint: s3-us-west-2.amazonaws.com + # region: us-west-2 + # secure: true + # accessKey: XXX + # secretKey: YYY + # # Below settings are optional #