feat: use CDN urls
This commit is contained in:
parent
39781de4e8
commit
0a42a32817
|
|
@ -268,6 +268,13 @@ export class MinioStorageService implements StorageService {
|
|||
await this.client.removeObject(this.bucketName, filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public URL for file access
|
||||
* Returns CDN URL if MINIO_PUBLIC_URL is configured (production),
|
||||
* otherwise falls back to API endpoint URL (development)
|
||||
*
|
||||
* @returns {string} URL for accessing the file
|
||||
*/
|
||||
getPublicUrl(
|
||||
orgId: string,
|
||||
projectId: string,
|
||||
|
|
@ -275,9 +282,21 @@ export class MinioStorageService implements StorageService {
|
|||
filename: string,
|
||||
): string {
|
||||
this.validateFilePath(orgId, projectId, category, filename);
|
||||
// Production-ready: Return API URL for presigned URL access
|
||||
|
||||
// If MINIO_PUBLIC_URL is configured, use direct CDN access
|
||||
// This provides better performance and reduces API server load
|
||||
if (this.publicUrl && process.env['USE_DIRECT_CDN'] !== 'false') {
|
||||
const filePath = this.getFilePath(orgId, projectId, category, filename);
|
||||
const cdnUrl = `${this.publicUrl}/${this.bucketName}/${filePath}`;
|
||||
console.log(`[MinIO] Using CDN URL: ${cdnUrl}`);
|
||||
return cdnUrl;
|
||||
}
|
||||
|
||||
// Fallback to API URL for local development or when CDN is disabled
|
||||
const apiBaseUrl = process.env['API_BASE_URL'] || 'http://localhost:3000';
|
||||
return `${apiBaseUrl}/api/images/${orgId}/${projectId}/${category}/${filename}`;
|
||||
const apiUrl = `${apiBaseUrl}/api/images/${orgId}/${projectId}/${category}/${filename}`;
|
||||
console.log(`[MinIO] Using API URL: ${apiUrl}`);
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
async getPresignedUploadUrl(
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ STORAGE_TYPE=minio
|
|||
# Public URL for CDN access (used in API responses)
|
||||
MINIO_PUBLIC_URL=https://cdn.banatie.app
|
||||
|
||||
# Use direct CDN URLs instead of API proxy (recommended for production)
|
||||
# Set to 'false' to force API URLs even when MINIO_PUBLIC_URL is configured
|
||||
# Default: true (CDN enabled when MINIO_PUBLIC_URL is present)
|
||||
USE_DIRECT_CDN=true
|
||||
|
||||
# ----------------------------------------
|
||||
# API Configuration
|
||||
# ----------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue