From 357322630da50f76fca4d3855a4726facbbc70ef Mon Sep 17 00:00:00 2001 From: Eric Bower Date: Mon, 6 Nov 2023 09:24:34 -0500 Subject: [PATCH] fix(imgs): better handling of 404 images --- filehandlers/imgs/handler.go | 4 ++-- imgs/api.go | 5 +++-- imgs/html/post.page.tmpl | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/filehandlers/imgs/handler.go b/filehandlers/imgs/handler.go index e18dae5a..d8ee6819 100644 --- a/filehandlers/imgs/handler.go +++ b/filehandlers/imgs/handler.go @@ -62,8 +62,8 @@ func (h *UploadImgHandler) removePost(data *PostMetaData) error { return nil } - err := h.DBPool.RemovePosts([]string{data.Post.ID}) - h.Cfg.Logger.Infof("(%s) is empty, removing record", data.Filename) + h.Cfg.Logger.Infof("(%s) is empty, removing record (%s)", data.Filename, data.Cur.ID) + err := h.DBPool.RemovePosts([]string{data.Cur.ID}) if err != nil { h.Cfg.Logger.Errorf("error for %s: %v", data.Filename, err) return fmt.Errorf("error for %s: %v", data.Filename, err) diff --git a/imgs/api.go b/imgs/api.go index 43b35e81..ac86c360 100644 --- a/imgs/api.go +++ b/imgs/api.go @@ -255,8 +255,9 @@ func imgHandler(w http.ResponseWriter, h *ImgHandler) { post, err := h.Dbpool.FindPostWithSlug(h.Slug, user.ID, h.Cfg.Space) if err != nil { - h.Logger.Infof("image not found %s/%s", h.Username, h.Slug) - http.Error(w, err.Error(), http.StatusInternalServerError) + errMsg := fmt.Sprintf("image not found %s/%s", h.Username, h.Slug) + h.Logger.Infof(errMsg) + http.Error(w, errMsg, http.StatusNotFound) return } diff --git a/imgs/html/post.page.tmpl b/imgs/html/post.page.tmpl index 62345c9a..fe071ff6 100644 --- a/imgs/html/post.page.tmpl +++ b/imgs/html/post.page.tmpl @@ -49,6 +49,7 @@
{{.Contents}}
+ {{if .ImgURL}}
Hotlink
{{.ImgURL}}
@@ -62,6 +63,7 @@
Resize width and height
{{.ImgURL}}/300x300
+ {{end}} {{template "footer" .}}