fix: user photo upload now INSIDE the main edit form (one Save = file+fields, no JS); admin resource FQNs corrected (relative Filament\Forms refs = panel-wide 500)

This commit is contained in:
2026-08-10 14:47:07 +10:00
parent fc7f3bf675
commit ef20af0d92
2 changed files with 28 additions and 18 deletions

View File

@@ -110,11 +110,33 @@ func (a *App) EditTag(w http.ResponseWriter, r *http.Request) {
return
}
// Optional file upload: if a photo file is present, store it and use it;
// otherwise fall back to the photo_url text value.
photoURL := strings.TrimSpace(r.FormValue("photo_url"))
if err := r.ParseMultipartForm(10 << 20); err == nil {
if file, header, ferr := r.FormFile("photo"); ferr == nil {
ct := header.Header.Get("Content-Type")
if strings.HasPrefix(ct, "image/") && a.Storage != nil {
ext := strings.ToLower(filepath.Ext(header.Filename))
if ext == "" {
ext = ".jpg"
}
key := fmt.Sprintf("tags/%d%s", tag.ID, ext)
if perr := a.Storage.Put(r.Context(), key, file, header.Size, ct); perr == nil {
photoURL = "/photos/" + key
}
file.Close()
} else if ferr == nil {
file.Close()
}
}
}
params := db.UpdateTagDetailsParams{
ID: tag.ID,
ItemType: textOrNil(strings.TrimSpace(r.FormValue("item_type"))),
Description: textOrNil(strings.TrimSpace(r.FormValue("description"))),
PhotoUrl: textOrNil(strings.TrimSpace(r.FormValue("photo_url"))),
PhotoUrl: textOrNil(photoURL),
Phone: textOrNil(strings.TrimSpace(r.FormValue("phone"))),
Address: textOrNil(strings.TrimSpace(r.FormValue("address"))),
Notes: textOrNil(strings.TrimSpace(r.FormValue("notes"))),