repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
3573226
parent
0d1a4be
author
Eric Bower
date
2023-11-06 14:24:34 +0000 UTC
fix(imgs): better handling of 404 images
3 files changed,  +7, -4
M filehandlers/imgs/handler.go
+2, -2
 1@@ -62,8 +62,8 @@ func (h *UploadImgHandler) removePost(data *PostMetaData) error {
 2 		return nil
 3 	}
 4 
 5-	err := h.DBPool.RemovePosts([]string{data.Post.ID})
 6-	h.Cfg.Logger.Infof("(%s) is empty, removing record", data.Filename)
 7+	h.Cfg.Logger.Infof("(%s) is empty, removing record (%s)", data.Filename, data.Cur.ID)
 8+	err := h.DBPool.RemovePosts([]string{data.Cur.ID})
 9 	if err != nil {
10 		h.Cfg.Logger.Errorf("error for %s: %v", data.Filename, err)
11 		return fmt.Errorf("error for %s: %v", data.Filename, err)
M imgs/api.go
+3, -2
 1@@ -255,8 +255,9 @@ func imgHandler(w http.ResponseWriter, h *ImgHandler) {
 2 
 3 	post, err := h.Dbpool.FindPostWithSlug(h.Slug, user.ID, h.Cfg.Space)
 4 	if err != nil {
 5-		h.Logger.Infof("image not found %s/%s", h.Username, h.Slug)
 6-		http.Error(w, err.Error(), http.StatusInternalServerError)
 7+		errMsg := fmt.Sprintf("image not found %s/%s", h.Username, h.Slug)
 8+		h.Logger.Infof(errMsg)
 9+		http.Error(w, errMsg, http.StatusNotFound)
10 		return
11 	}
12 
M imgs/html/post.page.tmpl
+2, -0
 1@@ -49,6 +49,7 @@
 2 
 3         <div class="md">{{.Contents}}</div>
 4 
 5+        {{if .ImgURL}}
 6         <dl>
 7             <dt>Hotlink</dt>
 8             <dd><a href="{{.ImgURL}}">{{.ImgURL}}</a></dd>
 9@@ -62,6 +63,7 @@
10             <dt>Resize width and height</dt>
11             <dd><a href="{{.ImgURL}}/300x300">{{.ImgURL}}/300x300</a></dd>
12         </dl>
13+        {{end}}
14     </article>
15 </main>
16 {{template "footer" .}}