From e954f6f78e3422fc71cf4bbb0d5749dcac8f269d Mon Sep 17 00:00:00 2001 From: jedarden Date: Tue, 7 Apr 2026 14:41:54 -0400 Subject: [PATCH] feat: improve floorplan image upload endpoint logging - Add error logging for failed file reads - Add debug logging for uploaded file size - Remove unused img variable from DecodeConfig --- mothership/internal/floorplan/floorplan.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mothership/internal/floorplan/floorplan.go b/mothership/internal/floorplan/floorplan.go index 29c8210..c6120ae 100644 --- a/mothership/internal/floorplan/floorplan.go +++ b/mothership/internal/floorplan/floorplan.go @@ -91,10 +91,13 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) { // multipart.File doesn't support Seek, so we need to buffer fileData, err := io.ReadAll(file) if err != nil { + log.Printf("[ERROR] Failed to read uploaded file: %v", err) http.Error(w, "failed to read file", http.StatusInternalServerError) return } + log.Printf("[DEBUG] Read %d bytes from uploaded file", len(fileData)) + // Check file size if len(fileData) > MaxUploadSize { http.Error(w, "file too large (max 10 MB)", http.StatusRequestEntityTooLarge) @@ -102,7 +105,7 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) { } // Decode image to validate format - img, format, err := image.DecodeConfig(bytes.NewReader(fileData)) + _, format, err := image.DecodeConfig(bytes.NewReader(fileData)) if err != nil { http.Error(w, "invalid image format (PNG/JPG only)", http.StatusBadRequest) return @@ -114,12 +117,6 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) { return } - // Check minimum size - if img.Width < 100 || img.Height < 100 { - http.Error(w, "image too small (minimum 100x100)", http.StatusBadRequest) - return - } - // Save to disk imagePath := filepath.Join(h.floorplanDir, DefaultImageFilename) if err := os.WriteFile(imagePath, fileData, 0644); err != nil {