From a2d3d22b6e9e8bdcc8eab295b7d020540bb1e413 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 14 Mar 2020 11:33:19 +0900 Subject: オブジェクトストレージでS3のvirtual-host形式のサポートなど (#6148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * オブジェクトストレージでS3のvirtual-host形式のサポートなど * 表記揺れ * more simply * S3ならばs3ForcePathStyleしない --- src/services/drive/add-file.ts | 3 ++- src/services/drive/s3.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/services') diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 2931de6dc0..cf0951ebad 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -217,7 +217,8 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string, const upload = s3.upload(params); - await upload.promise(); + const result = await upload.promise(); + if (result) logger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`); } async function deleteOldFile(user: IRemoteUser) { diff --git a/src/services/drive/s3.ts b/src/services/drive/s3.ts index 95243d5901..d136bb2694 100644 --- a/src/services/drive/s3.ts +++ b/src/services/drive/s3.ts @@ -1,23 +1,23 @@ import * as S3 from 'aws-sdk/clients/s3'; import config from '../../config'; import { Meta } from '../../models/entities/meta'; -import * as httpsProxyAgent from 'https-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; import * as agentkeepalive from 'agentkeepalive'; const httpsAgent = config.proxy - ? new httpsProxyAgent(config.proxy) + ? new HttpsProxyAgent(config.proxy) : new agentkeepalive.HttpsAgent({ freeSocketTimeout: 30 * 1000 }); export function getS3(meta: Meta) { const conf = { - endpoint: meta.objectStorageEndpoint, + endpoint: meta.objectStorageEndpoint || undefined, accessKeyId: meta.objectStorageAccessKey, secretAccessKey: meta.objectStorageSecretKey, - region: meta.objectStorageRegion, + region: meta.objectStorageRegion || undefined, sslEnabled: meta.objectStorageUseSSL, - s3ForcePathStyle: true, + s3ForcePathStyle: !!meta.objectStorageEndpoint, httpOptions: { } } as S3.ClientConfiguration; -- cgit v1.2.3-freya