feat: verify user's avatar + full url for profile picture

This commit is contained in:
2025-06-07 02:09:10 +02:00
parent 715a984241
commit a27f2ad593

View File

@ -180,8 +180,16 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) {
return
}
if !user.AvatarVerified {
if err := h.repo.UserVerifyAvatar(r.Context(), user.ID); err != nil {
log.Println("ERR: Failed to update avatar_verified:", err)
web.Error(w, "failed to verify avatar", http.StatusInternalServerError)
return
}
}
type Response struct {
AvatarID string `json:"url"`
URL string `json:"url"`
}
w.Header().Set("Content-Type", "application/json")
@ -190,7 +198,7 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{AvatarID: uploadInfo.Key}); err != nil {
if err := encoder.Encode(Response{URL: fmt.Sprintf("%s/avatar/%s", h.cfg.Uri, uploadInfo.Key)}); err != nil {
web.Error(w, "failed to write response", http.StatusInternalServerError)
}
}