Skip to content

Commit

Permalink
fix(imgs): better handling of 404 images
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Nov 6, 2023
1 parent 0d1a4be commit 3573226
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions filehandlers/imgs/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions imgs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions imgs/html/post.page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

<div class="md">{{.Contents}}</div>

{{if .ImgURL}}
<dl>
<dt>Hotlink</dt>
<dd><a href="{{.ImgURL}}">{{.ImgURL}}</a></dd>
Expand All @@ -62,6 +63,7 @@
<dt>Resize width and height</dt>
<dd><a href="{{.ImgURL}}/300x300">{{.ImgURL}}/300x300</a></dd>
</dl>
{{end}}
</article>
</main>
{{template "footer" .}}
Expand Down

0 comments on commit 3573226

Please sign in to comment.