repos / pico

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

commit
77c71a2
parent
c774b03
author
Eric Bower
date
2022-08-23 03:08:52 +0000 UTC
fix(imgs): use updated shasum logic
3 files changed,  +7, -6
M filehandlers/imgs/handler.go
+2, -3
 1@@ -18,7 +18,6 @@ import (
 2 
 3 var GB = 1024 * 1024 * 1024
 4 var maxSize = 2 * GB
 5-var mdMime = "text/markdown; charset=UTF-8"
 6 
 7 type PostMetaData struct {
 8 	*db.Post
 9@@ -110,8 +109,8 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
10 		nextPost.MimeType = "text/markdown; charset=UTF-8"
11 	}
12 
13-	post, err := h.DBPool.FindPostWithSlug(
14-		nextPost.Slug,
15+	post, err := h.DBPool.FindPostWithFilename(
16+		nextPost.Filename,
17 		h.User.ID,
18 		h.Cfg.Space,
19 	)
M filehandlers/imgs/img.go
+1, -1
1@@ -116,7 +116,7 @@ func (h *UploadImgHandler) writeImg(data *PostMetaData) error {
2 			}
3 		}
4 	} else {
5-		if shared.Shasum(data.OrigText) == data.Cur.Shasum {
6+		if data.Shasum == data.Cur.Shasum {
7 			h.Cfg.Logger.Infof("(%s) found, but image is identical, skipping", data.Filename)
8 			return nil
9 		}
M shared/util.go
+4, -2
 1@@ -120,6 +120,8 @@ func TimeAgo(t *time.Time) string {
 2 }
 3 
 4 func Shasum(data []byte) string {
 5-	hash := sha256.Sum256(data)
 6-	return hex.EncodeToString(hash[:])
 7+	h := sha256.New()
 8+	h.Write(data)
 9+	bs := h.Sum(nil)
10+	return hex.EncodeToString(bs)
11 }