Skip to content

Commit fe320a6

Browse files
committed
Update Deploy
1 parent 644ba3b commit fe320a6

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

FileService/.idea/.idea.FileService/.idea/workspace.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FileService/FileService.Api/appsettings.Staging.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"MinioConfig": {
3838
"Endpoint": "minio",
3939
// giữ cho giao tiếp nội bộ
40-
"PublicEndpoint": "codecampus.site",
40+
"PublicEndpoint": "https://codecampus.site/s3",
4141
// cho browser truy cập
4242
"Port": 9000,
4343
"AccessKey": "${MINIO_ROOT_USER}",

FileService/FileService.Service/Implementation/MinioService.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,31 @@ public async Task UploadStreamAsync(string objectName, Stream fileStream, string
146146
}
147147
public Task<string> GetPublicFileUrlAsync(string objectName)
148148
{
149-
if (string.IsNullOrWhiteSpace(objectName) || objectName.Any(c => "!@#$%^&*()".Contains(c)))
150-
{
149+
if (string.IsNullOrWhiteSpace(objectName))
151150
throw new ArgumentException("Invalid object name", nameof(objectName));
152-
}
153151

154-
var endpoint = !string.IsNullOrWhiteSpace(_config.PublicEndpoint) ? _config.PublicEndpoint : _config.Endpoint;// Ưu tiên PublicEndpoint
152+
var key = Uri.EscapeDataString(objectName);
153+
154+
// Nếu có PublicEndpoint thì dùng nó làm base (có thể gồm scheme + path), KHÔNG thêm :port
155+
var pub = _config.PublicEndpoint?.Trim().TrimEnd('/');
156+
if (!string.IsNullOrEmpty(pub))
157+
{
158+
// Nếu thiếu scheme thì tự thêm theo cấu hình Secure
159+
if (!pub.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
160+
!pub.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
161+
{
162+
pub = $"{(_config.Secure ? "https" : "http")}://{pub}";
163+
}
164+
var url = $"{pub}/{_config.BucketName}/{key}";
165+
Console.WriteLine($"Generated public URL: {url}");
166+
return Task.FromResult(url);
167+
}
155168

156-
var url = $"{(_config.Secure ? "https" : "http")}://{endpoint}:{_config.Port}/{_config.BucketName}/{objectName}";
157-
Console.WriteLine($"Generated URL: {url}");
158-
return Task.FromResult(url);
169+
// Fallback: dùng endpoint nội bộ (có :port)
170+
var scheme = _config.Secure ? "https" : "http";
171+
var direct = $"{scheme}://{_config.Endpoint}:{_config.Port}/{_config.BucketName}/{key}";
172+
Console.WriteLine($"Generated direct URL: {direct}");
173+
return Task.FromResult(direct);
159174
}
160175

161176
public async Task<string> GeneratePresignedUrlAsync(string objectName, int expirySeconds)

docker-compose.prod-services.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ services:
188188
- MongoDbSettings__DatabaseName=${FILE_DATABASE}
189189
- AppSettings__ApiSettings__UserServiceBaseUrl=http://profile-service:8081
190190
- AppSettings__MinioConfig__Endpoint=minio
191-
- AppSettings__MinioConfig__PublicEndpoint=codecampus.site
192-
- AppSettings__MinioConfig__Port=9000
191+
- AppSettings__MinioConfig__PublicEndpoint=https://codecampus.site/s3
193192
- AppSettings__MinioConfig__AccessKey=${MINIO_ROOT_USER}
194193
- AppSettings__MinioConfig__SecretKey=${MINIO_ROOT_PASSWORD}
195194
- AppSettings__MinioConfig__BucketName=codecampus2025

0 commit comments

Comments
 (0)