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

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

35
src/lib/imageProxy.ts Normal file
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;
}