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