diff --git a/Backend/src/services/user.service.ts b/Backend/src/services/user.service.ts index 752d3b3f..88037f49 100644 --- a/Backend/src/services/user.service.ts +++ b/Backend/src/services/user.service.ts @@ -207,11 +207,8 @@ export class UserService { // Delete old avatar if exists if (user.profile?.avatar_url) { try { - // Extract file path from URL - const urlParts = user.profile.avatar_url.split('/'); - const oldFilePath = urlParts.slice(-2).join('/'); // Get avatars/{userId}/{filename} - await deleteFile(oldFilePath); - logger.info(`Deleted old avatar: ${oldFilePath}`); + await deleteFile(user.profile.avatar_url); + logger.info(`Deleted old avatar: ${user.profile.avatar_url}`); } catch (error) { logger.warn(`Failed to delete old avatar: ${error}`); // Continue with upload even if delete fails @@ -221,6 +218,7 @@ export class UserService { // Upload to MinIO await uploadFile(filePath, file.buffer, file.mimetype || 'image/jpeg'); + logger.info(`Uploaded avatar: ${filePath}`); // Update or create profile - store only file path if (user.profile) { await prisma.userProfile.update({ @@ -272,7 +270,7 @@ export class UserService { return await getPresignedUrl(avatarPath, 3600); // 1 hour expiry } catch (error) { logger.warn(`Failed to generate presigned URL for avatar: ${error}`); - return ''; + throw error; } }