HTTPリクエストのKeep-AliveとPrxoy対応など (#5226)

* DriveのKeep-Alive, Proxy と APのProxy対応

* request系でKeep-Aliveするように

* fix lookup-dns-cache.d.ts

* remove debug output
This commit is contained in:
MeiMei
2019-07-28 09:49:02 +09:00
committed by syuilo
parent 831ca53b63
commit 14736620ec
11 changed files with 151 additions and 176 deletions

View File

@@ -2,7 +2,6 @@ import { Buffer } from 'buffer';
import * as fs from 'fs';
import * as crypto from 'crypto';
import * as Minio from 'minio';
import * as uuid from 'uuid';
import * as sharp from 'sharp';
@@ -21,6 +20,8 @@ import { IRemoteUser, User } from '../../models/entities/user';
import { driveChart, perUserDriveChart, instanceChart } from '../chart';
import { genId } from '../../misc/gen-id';
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
import * as S3 from 'aws-sdk/clients/s3';
import { getS3 } from './s3';
const logger = driveLogger.createSubLogger('register', 'yellow');
@@ -211,23 +212,21 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string,
const meta = await fetchMeta();
const minio = new Minio.Client({
endPoint: meta.objectStorageEndpoint!,
region: meta.objectStorageRegion ? meta.objectStorageRegion : undefined,
port: meta.objectStoragePort ? meta.objectStoragePort : undefined,
useSSL: meta.objectStorageUseSSL,
accessKey: meta.objectStorageAccessKey!,
secretKey: meta.objectStorageSecretKey!,
});
const params = {
Bucket: meta.objectStorageBucket,
Key: key,
Body: stream,
ContentType: type,
CacheControl: 'max-age=31536000, immutable',
} as S3.PutObjectRequest;
const metadata = {
'Content-Type': type,
'Cache-Control': 'max-age=31536000, immutable'
} as Minio.ItemBucketMetadata;
if (filename) params.ContentDisposition = contentDisposition('inline', filename);
if (filename) metadata['Content-Disposition'] = contentDisposition('inline', filename);
const s3 = getS3(meta);
await minio.putObject(meta.objectStorageBucket!, key, stream, undefined, metadata);
const upload = s3.upload(params);
await upload.promise();
}
async function deleteOldFile(user: IRemoteUser) {

View File

@@ -1,10 +1,10 @@
import * as Minio from 'minio';
import { DriveFile } from '../../models/entities/drive-file';
import { InternalStorage } from './internal-storage';
import { DriveFiles, Instances, Notes } from '../../models';
import { driveChart, perUserDriveChart, instanceChart } from '../chart';
import { createDeleteObjectStorageFileJob } from '../../queue';
import { fetchMeta } from '../../misc/fetch-meta';
import { getS3 } from './s3';
export async function deleteFile(file: DriveFile, isExpired = false) {
if (file.storedInternal) {
@@ -93,14 +93,10 @@ function postProcess(file: DriveFile, isExpired = false) {
export async function deleteObjectStorageFile(key: string) {
const meta = await fetchMeta();
const minio = new Minio.Client({
endPoint: meta.objectStorageEndpoint!,
region: meta.objectStorageRegion ? meta.objectStorageRegion : undefined,
port: meta.objectStoragePort ? meta.objectStoragePort : undefined,
useSSL: meta.objectStorageUseSSL,
accessKey: meta.objectStorageAccessKey!,
secretKey: meta.objectStorageSecretKey!,
});
const s3 = getS3(meta);
await minio.removeObject(meta.objectStorageBucket!, key);
await s3.deleteObject({
Bucket: meta.objectStorageBucket!,
Key: key
}).promise();
}

31
src/services/drive/s3.ts Normal file
View File

@@ -0,0 +1,31 @@
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 * as agentkeepalive from 'agentkeepalive';
const httpsAgent = config.proxy
? new httpsProxyAgent(config.proxy)
: new agentkeepalive.HttpsAgent({
freeSocketTimeout: 30 * 1000
});
export function getS3(meta: Meta) {
const conf = {
endpoint: meta.objectStorageEndpoint,
accessKeyId: meta.objectStorageAccessKey,
secretAccessKey: meta.objectStorageSecretKey,
region: meta.objectStorageRegion,
sslEnabled: meta.objectStorageUseSSL,
httpOptions: {
}
} as S3.ClientConfiguration;
if (meta.objectStorageUseSSL) {
conf.httpOptions!.agent = httpsAgent;
}
const s3 = new S3(conf);
return s3;
}