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