修改头像bug
This commit is contained in:
+7
-2
@@ -91,7 +91,13 @@ func UpdateProfile(db *gorm.DB, storagePath string) gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use user ID as filename base to avoid duplicates.
|
// Remove old avatar file if it exists (different extension or same).
|
||||||
|
if user.Avatar != "" {
|
||||||
|
oldPath := filepath.Join(avatarDir, user.Avatar)
|
||||||
|
os.Remove(oldPath) // ignore error — file may not exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use user ID as filename base.
|
||||||
savedName := fmt.Sprintf("%d%s", user.ID, ext)
|
savedName := fmt.Sprintf("%d%s", user.ID, ext)
|
||||||
savedPath := filepath.Join(avatarDir, savedName)
|
savedPath := filepath.Join(avatarDir, savedName)
|
||||||
|
|
||||||
@@ -108,7 +114,6 @@ func UpdateProfile(db *gorm.DB, storagePath string) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.Avatar = savedName
|
user.Avatar = savedName
|
||||||
// Update session display immediately.
|
|
||||||
session.Set("avatar", savedName)
|
session.Set("avatar", savedName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user