Skip to content

Commit 6452b36

Browse files
authored
fix: s3 client (#317)
1 parent ff322ed commit 6452b36

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

lib/s3/controller.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,8 @@ export class S3Service {
151151
const externalBaseURL = this.config.externalBaseURL;
152152

153153
// Private
154-
if (!this.config.isPublicRead) {
155-
const url = await this.client.presignedGetObject(this.config.bucket, objectName, expiry);
156-
// 如果有 externalBaseUrl,需要把域名进行替换
157-
if (this.config.externalBaseURL) {
158-
const urlObj = new URL(url);
159-
const externalUrlObj = new URL(this.config.externalBaseURL);
160-
161-
// 替换协议和域名,保留路径和查询参数
162-
urlObj.protocol = externalUrlObj.protocol;
163-
urlObj.hostname = externalUrlObj.hostname;
164-
urlObj.port = externalUrlObj.port;
165-
166-
return urlObj.toString();
167-
}
168-
169-
return url;
154+
if (!this.config.isPublicRead && this.externalClient) {
155+
return await this.externalClient.presignedGetObject(this.config.bucket, objectName, expiry);
170156
}
171157

172158
// Public
@@ -331,13 +317,11 @@ export class S3Service {
331317
const name = this.generateFileId();
332318
const objectName = `${filepath}/${name}`;
333319

334-
if (fileExpireMins) {
335-
await MongoS3TTL.create({
336-
bucketName: this.config.bucket,
337-
minioKey: objectName,
338-
expiredTime: addMinutes(new Date(), fileExpireMins)
339-
});
340-
}
320+
await MongoS3TTL.create({
321+
bucketName: this.config.bucket,
322+
minioKey: objectName,
323+
expiredTime: addMinutes(new Date(), fileExpireMins ?? 60)
324+
});
341325

342326
const client = this.externalClient ?? this.client;
343327

@@ -370,11 +354,6 @@ export class S3Service {
370354
}
371355
})();
372356

373-
await MongoS3TTL.create({
374-
bucketName: this.config.bucket,
375-
expiredTime: new Date(Date.now() + 10 * 60 * 1000),
376-
minioKey: objectName
377-
});
378357
return {
379358
postURL,
380359
formData: res.formData,

runtime/.env.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ S3_ACCESS_KEY=minioadmin
2121
S3_SECRET_KEY=minioadmin
2222
S3_PUBLIC_BUCKET=fastgpt-public # 公开读私有写桶。用于系统工具,创建的临时文件,存储的桶。
2323
S3_PRIVATE_BUCKET=fastgpt-private # 私有读写桶。用于系统插件热安装文件的桶。
24-
S3_PATH_STYLE=true #pathStyle 模式 默认true
25-
# S3_REGION=
24+
S3_PATH_STYLE=true # pathStyle 模式,默认 true
25+
S3_REGION=
2626

2727
# Signoz
2828
SIGNOZ_BASE_URL=

0 commit comments

Comments
 (0)