feat: Implement S3 presigned URL fetching for user avatars and add an image proxy utility.

This commit is contained in:
pradeepkumar committed 2026-01-26 22:43:41 +05:30
1 parent 4962f9a625
commit a061b14914
4 files changed
+105 -4

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
/**
* Convert avatar URL to proper backend URL
* Handles both S3 URLs and relative backend paths
*/
export function getProxyImageUrl(url: string | null | undefined): string {
if (!url) {
return '';
}
// If it's a data URL, return as-is
if (url.startsWith('data:')) {
return url;
}
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api/v1';
const apiBaseUrl = apiUrl.replace('/api/v1', '');
// If it's a relative path from backend (like /development/avatars/...)
// Prefix with backend base URL
if (url.startsWith('/development/') || url.startsWith('/uploads/') || url.startsWith('/avatars/')) {
return `${apiBaseUrl}${url}`;
}
// If it's an S3/external URL, proxy through backend
if (url.startsWith('http')) {
return `${apiUrl}/upload/image?url=${encodeURIComponent(url)}`;
}
// For other relative paths, assume they're backend paths
if (url.startsWith('/')) {
return `${apiBaseUrl}${url}`;
}
return url;
}