オブジェクトストレージでS3のvirtual-host形式のサポートなど (#6148)
* オブジェクトストレージでS3のvirtual-host形式のサポートなど * 表記揺れ * more simply * S3ならばs3ForcePathStyleしない
This commit is contained in:
		
							parent
							
								
									1ad8603cc2
								
							
						
					
					
						commit
						a2d3d22b6e
					
				
					 5 changed files with 27 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -102,21 +102,20 @@
 | 
			
		|||
		<div class="_content">
 | 
			
		||||
			<mk-switch v-model="useObjectStorage">{{ $t('useObjectStorage') }}</mk-switch>
 | 
			
		||||
			<template v-if="useObjectStorage">
 | 
			
		||||
				<mk-input v-model="objectStorageBaseUrl" :disabled="!useObjectStorage">URL</mk-input>
 | 
			
		||||
				<mk-input v-model="objectStorageBaseUrl" :disabled="!useObjectStorage">{{ $t('objectStorageBaseUrl') }}<template #desc>{{ $t('objectStorageBaseUrlDesc') }}</template></mk-input>
 | 
			
		||||
				<div class="_inputs">
 | 
			
		||||
					<mk-input v-model="objectStorageBucket" :disabled="!useObjectStorage">Bucket</mk-input>
 | 
			
		||||
					<mk-input v-model="objectStoragePrefix" :disabled="!useObjectStorage">Prefix</mk-input>
 | 
			
		||||
					<mk-input v-model="objectStorageBucket" :disabled="!useObjectStorage">{{ $t('objectStorageBucket') }}<template #desc>{{ $t('objectStorageBucketDesc') }}</template></mk-input>
 | 
			
		||||
					<mk-input v-model="objectStoragePrefix" :disabled="!useObjectStorage">{{ $t('objectStoragePrefix') }}<template #desc>{{ $t('objectStoragePrefixDesc') }}</template></mk-input>
 | 
			
		||||
				</div>
 | 
			
		||||
				<mk-input v-model="objectStorageEndpoint" :disabled="!useObjectStorage">Endpoint</mk-input>
 | 
			
		||||
				<mk-input v-model="objectStorageEndpoint" :disabled="!useObjectStorage">{{ $t('objectStorageEndpoint') }}<template #desc>{{ $t('objectStorageEndpointDesc') }}</template></mk-input>
 | 
			
		||||
				<div class="_inputs">
 | 
			
		||||
					<mk-input v-model="objectStorageRegion" :disabled="!useObjectStorage">Region</mk-input>
 | 
			
		||||
					<mk-input v-model="objectStoragePort" type="number" :disabled="!useObjectStorage">Port</mk-input>
 | 
			
		||||
					<mk-input v-model="objectStorageRegion" :disabled="!useObjectStorage">{{ $t('objectStorageRegion') }}<template #desc>{{ $t('objectStorageRegionDesc') }}</template></mk-input>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div class="_inputs">
 | 
			
		||||
					<mk-input v-model="objectStorageAccessKey" :disabled="!useObjectStorage"><template #icon><fa :icon="faKey"/></template>Access key</mk-input>
 | 
			
		||||
					<mk-input v-model="objectStorageSecretKey" :disabled="!useObjectStorage"><template #icon><fa :icon="faKey"/></template>Secret key</mk-input>
 | 
			
		||||
				</div>
 | 
			
		||||
				<mk-switch v-model="objectStorageUseSSL" :disabled="!useObjectStorage">SSL</mk-switch>
 | 
			
		||||
				<mk-switch v-model="objectStorageUseSSL" :disabled="!useObjectStorage">{{ $t('objectStorageUseSSL') }}<template #desc>{{ $t('objectStorageUseSSLDesc') }}</template></mk-switch>
 | 
			
		||||
			</template>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class="_footer">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,10 +7,10 @@ import config from '../../config';
 | 
			
		|||
import { ILocalUser } from '../../models/entities/user';
 | 
			
		||||
import { UserKeypairs } from '../../models';
 | 
			
		||||
import { ensure } from '../../prelude/ensure';
 | 
			
		||||
import * as httpsProxyAgent from 'https-proxy-agent';
 | 
			
		||||
import { HttpsProxyAgent } from 'https-proxy-agent';
 | 
			
		||||
 | 
			
		||||
const agent = config.proxy
 | 
			
		||||
	? new httpsProxyAgent(config.proxy)
 | 
			
		||||
	? new HttpsProxyAgent(config.proxy)
 | 
			
		||||
	: new https.Agent({
 | 
			
		||||
			lookup: cache.lookup,
 | 
			
		||||
		});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -217,7 +217,8 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string,
 | 
			
		|||
 | 
			
		||||
	const upload = s3.upload(params);
 | 
			
		||||
 | 
			
		||||
	await upload.promise();
 | 
			
		||||
	const result = await upload.promise();
 | 
			
		||||
	if (result) logger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function deleteOldFile(user: IRemoteUser) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,23 +1,23 @@
 | 
			
		|||
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 { HttpsProxyAgent } from 'https-proxy-agent';
 | 
			
		||||
import * as agentkeepalive from 'agentkeepalive';
 | 
			
		||||
 | 
			
		||||
const httpsAgent = config.proxy
 | 
			
		||||
	? new httpsProxyAgent(config.proxy)
 | 
			
		||||
	? new HttpsProxyAgent(config.proxy)
 | 
			
		||||
	: new agentkeepalive.HttpsAgent({
 | 
			
		||||
			freeSocketTimeout: 30 * 1000
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
export function getS3(meta: Meta) {
 | 
			
		||||
	const conf = {
 | 
			
		||||
		endpoint: meta.objectStorageEndpoint,
 | 
			
		||||
		endpoint: meta.objectStorageEndpoint || undefined,
 | 
			
		||||
		accessKeyId: meta.objectStorageAccessKey,
 | 
			
		||||
		secretAccessKey: meta.objectStorageSecretKey,
 | 
			
		||||
		region: meta.objectStorageRegion,
 | 
			
		||||
		region: meta.objectStorageRegion || undefined,
 | 
			
		||||
		sslEnabled: meta.objectStorageUseSSL,
 | 
			
		||||
		s3ForcePathStyle: true,
 | 
			
		||||
		s3ForcePathStyle: !!meta.objectStorageEndpoint,
 | 
			
		||||
		httpOptions: {
 | 
			
		||||
		}
 | 
			
		||||
	} as S3.ClientConfiguration;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue