iceshrimp-legacy/src/services/drive/s3.ts
MeiMei 36b9a0d42f
プロキシの除外ホスト (#6244)
* プロキシの除外ホスト

* オブジェクトストレージとの通信にProxyを使うかを選択できるように

* fix lint

* コメント

Co-authored-by: rinsuki <428rinsuki+git@gmail.com>
2020-04-12 20:32:34 +09:00

22 lines
782 B
TypeScript

import * as S3 from 'aws-sdk/clients/s3';
import { Meta } from '../../models/entities/meta';
import { getAgentByUrl } from '../../misc/fetch';
export function getS3(meta: Meta) {
const u = meta.objectStorageEndpoint != null
? `${meta.objectStorageUseSSL ? 'https://' : 'http://'}${meta.objectStorageEndpoint}`
: `${meta.objectStorageUseSSL ? 'https://' : 'http://'}example.net`;
return new S3({
endpoint: meta.objectStorageEndpoint || undefined,
accessKeyId: meta.objectStorageAccessKey!,
secretAccessKey: meta.objectStorageSecretKey!,
region: meta.objectStorageRegion || undefined,
sslEnabled: meta.objectStorageUseSSL,
s3ForcePathStyle: !!meta.objectStorageEndpoint,
httpOptions: {
agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy)
}
});
}