From 5c91623d25bc45df7243df9045d6ff552ec7a340 Mon Sep 17 00:00:00 2001 From: Steve White Date: Thu, 10 Oct 2024 17:16:56 -0500 Subject: [PATCH] fixing image display one step at a time. Removing .DS_Store --- .DS_Store | Bin 8196 -> 0 bytes .gitignore | 2 +- handlers.go | 18 ++++++++---------- 3 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index a9bd2e7ab39d30aa8088a95cbf10fcd1b9e14f7b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM!EVz)5S?w)ByLsIqE?gxk|nOCv{iv3E+M3c9=J3W8~}wl35nIj8^wu&R2Ah4 z`~$zhkw4*IIKi7)r`S&1BSP(Nv^$&Kd9yoj)^^4rB2^wW_lUNLsEEpPZ3WGo!t-2b z%0e`<38{c58d8gTbV{1aGun2*GGH073|Iy%1D1jRfdM?TxfC;=`)1a*mI2GajbwoD z4=yUpQY0rv%B=&9qyUgP3`;>Dd4OQtNR}cwF;bwgX|e|uK~*Xl%4M>J9lBZk54y+t-xjo zYXgk;ud=A_r7Sw|fIVUS1GCHI9@N(qB9C==zr6o;O7~Yv*NN-G!#3$8VxgTvPqyI#XbMvkcsL22`$6t&~B- z^y!{vgmY~d^*t&V)|(h95HymGLrOXhdHIJS`Yu!%Q;OuoNQ|KT`xgP}WQKqI+2_9m J!!|dDfj@4eZZiM? diff --git a/.gitignore b/.gitignore index 2d7189a..9495ca7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ data/* images/* -.DS_Store \ No newline at end of file +.DS_Store diff --git a/handlers.go b/handlers.go index 92fa3f1..e84636a 100644 --- a/handlers.go +++ b/handlers.go @@ -231,20 +231,17 @@ func GetItemImageHandler(w http.ResponseWriter, r *http.Request) { // Retrieve the item from the database var item Item if err := db.First(&item, itemID).Error; err != nil { - http.Error(w, "Item not found", http.StatusNotFound) - return - } - - // Check if the item has an associated image - if item.ImagePath == "" { - http.Error(w, "Item has no image", http.StatusNotFound) - return + item.ImagePath = "images/default.jpg" + } else if item.ImagePath == "" { + item.ImagePath = "images/default.jpg" } // Open the image file imageFile, err := os.Open(item.ImagePath) if err != nil { - http.Error(w, "Unable to open image file", http.StatusInternalServerError) + // Log the error for debugging, but don't return an HTTP error + fmt.Println("Error opening image.", err) + item.ImagePath = "images/default.png" return } defer imageFile.Close() @@ -252,7 +249,8 @@ func GetItemImageHandler(w http.ResponseWriter, r *http.Request) { // Determine the content type of the image imageData, err := io.ReadAll(imageFile) if err != nil { - http.Error(w, "Unable to read image file", http.StatusInternalServerError) + fmt.Println("Error reading image") + item.ImagePath = "images/default.png" return } contentType := http.DetectContentType(imageData)