fix: update file URL handling for production - supports both old and new URL formats
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user