fix: update file URL handling for production - supports both old and new URL formats

This commit is contained in:
Erik Silva
2026-01-20 23:01:50 -03:00
parent 1959047d75
commit ec962a7081
2 changed files with 41 additions and 13 deletions

View File

@@ -13,15 +13,22 @@ function xorEncrypt(data: Uint8Array, key: string): Uint8Array {
// Get internal MinIO URL for server-side fetching
function getInternalFileUrl(fileUrl: string): string {
const minioEndpoint = process.env.MINIO_ENDPOINT || 'minio';
const minioPort = process.env.MINIO_PORT || '9000';
try {
// Format 1: /api/files/bucket/filename (new relative URL)
if (fileUrl.startsWith('/api/files/')) {
const pathPart = fileUrl.replace('/api/files/', '');
return `http://${minioEndpoint}:${minioPort}/${pathPart}`;
}
// Format 2: http://host:port/bucket/filename (old absolute URL)
const url = new URL(fileUrl);
// Extract bucket and file path from URL
const pathParts = url.pathname.split('/').filter(Boolean);
if (pathParts.length >= 2) {
const bucket = pathParts[0];
const fileName = pathParts.slice(1).join('/');
const minioEndpoint = process.env.MINIO_ENDPOINT || 'minio';
const minioPort = process.env.MINIO_PORT || '9000';
return `http://${minioEndpoint}:${minioPort}/${bucket}/${fileName}`;
}
} catch (e) {