Fix avatar reupload

This commit is contained in:
blankhex committed 2026-10-16 12:19:17 +03:00
1 parent e45959ddd9
commit 0f0eb39b37
1 file changed
+9
+9
View File
@@ -66,12 +66,21 @@ func (s *WebService) HandleProfileEdit(w http.ResponseWriter, r *http.Request) {
s.render(w, r, "profile/edit.html", data)
return
}
// Check if the user already has an avatar; if so update, otherwise insert.
if _, err := s.users.GetAvatar(r.Context(), data.User.Id); err == nil {
if err := s.users.UpdateAvatar(r.Context(), data.User.Id, bytes); err != nil {
data.Error = "Could not save avatar"
s.render(w, r, "profile/edit.html", data)
return
}
} else {
if err := s.users.CreateAvatar(r.Context(), data.User.Id, bytes); err != nil {
data.Error = "Could not save avatar"
s.render(w, r, "profile/edit.html", data)
return
}
}
}
http.Redirect(w, r, "/profile", http.StatusSeeOther)
}