2021-03-24 02:05:37 +00:00
|
|
|
import { URL } from 'url';
|
2019-07-28 00:49:02 +00:00
|
|
|
import * as S3 from 'aws-sdk/clients/s3';
|
2021-08-19 12:55:45 +00:00
|
|
|
import { Meta } from '@/models/entities/meta';
|
|
|
|
import { getAgentByUrl } from '@/misc/fetch';
|
2019-07-28 00:49:02 +00:00
|
|
|
|
|
|
|
export function getS3(meta: Meta) {
|
2020-04-12 11:32:34 +00:00
|
|
|
const u = meta.objectStorageEndpoint != null
|
|
|
|
? `${meta.objectStorageUseSSL ? 'https://' : 'http://'}${meta.objectStorageEndpoint}`
|
|
|
|
: `${meta.objectStorageUseSSL ? 'https://' : 'http://'}example.net`;
|
|
|
|
|
2020-04-09 14:42:23 +00:00
|
|
|
return new S3({
|
2020-03-14 02:33:19 +00:00
|
|
|
endpoint: meta.objectStorageEndpoint || undefined,
|
2020-04-09 14:42:23 +00:00
|
|
|
accessKeyId: meta.objectStorageAccessKey!,
|
|
|
|
secretAccessKey: meta.objectStorageSecretKey!,
|
2020-03-14 02:33:19 +00:00
|
|
|
region: meta.objectStorageRegion || undefined,
|
2019-07-28 00:49:02 +00:00
|
|
|
sslEnabled: meta.objectStorageUseSSL,
|
2021-02-06 02:48:57 +00:00
|
|
|
s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted
|
|
|
|
? false
|
|
|
|
: meta.objectStorageS3ForcePathStyle,
|
2019-07-28 00:49:02 +00:00
|
|
|
httpOptions: {
|
2021-12-09 14:58:30 +00:00
|
|
|
agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy),
|
|
|
|
},
|
2020-04-09 14:42:23 +00:00
|
|
|
});
|
2019-07-28 00:49:02 +00:00
|
|
|
}
|