From 04a0b28fd729d02fa1a085bb9cffbdd17a227f8e Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 4 Jan 2023 00:16:45 +0800 Subject: [PATCH] fix(file): set minio region --- src/file/file.service.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/file/file.service.ts b/src/file/file.service.ts index f6660d8..4e0bdf1 100644 --- a/src/file/file.service.ts +++ b/src/file/file.service.ts @@ -6,7 +6,7 @@ import { InjectRepository, InjectDataSource } from "@nestjs/typeorm"; import { Repository, DataSource, EntityManager, In } from "typeorm"; import { v4 as UUID } from "uuid"; -import { Client as MinioClient } from "minio"; +import { Client as MinioClient, ClientOptions } from "minio"; import { logger } from "@/logger"; import { ConfigService } from "@/config/config.service"; @@ -101,35 +101,36 @@ export class FileService implements OnModuleInit { private readonly configService: ConfigService ) { const config = this.configService.config.services.minio; + const commonOptions: Pick = { + accessKey: config.accessKey, + secretKey: config.secretKey, + region: "us-east-1" + }; this.minioClient = new MinioClient({ ...parseMainEndpointUrl(config.default.endpoint), - accessKey: config.accessKey, - secretKey: config.secretKey + ...commonOptions }); this.bucket = config.bucket; this.minioSigner = { [MinioSignFor.UserUpload]: { client: new MinioClient({ ...parseMainEndpointUrl(config?.forUserUpload?.endpoint || config.default.endpoint), - accessKey: config.accessKey, - secretKey: config.secretKey + ...commonOptions }), replaceUrl: parseSignEndpointUrl(config?.forUserUpload?.urlEndpoint || config.default.urlEndpoint) }, [MinioSignFor.UserDownload]: { client: new MinioClient({ ...parseMainEndpointUrl(config?.forUserDownload?.endpoint || config.default.endpoint), - accessKey: config.accessKey, - secretKey: config.secretKey + ...commonOptions }), replaceUrl: parseSignEndpointUrl(config?.forUserDownload?.urlEndpoint || config.default.urlEndpoint) }, [MinioSignFor.Judge]: { client: new MinioClient({ ...parseMainEndpointUrl(config?.forJudge?.endpoint || config.default.endpoint), - accessKey: config.accessKey, - secretKey: config.secretKey + ...commonOptions }), replaceUrl: parseSignEndpointUrl(config?.forJudge?.urlEndpoint || config.default.urlEndpoint) }