- commit
- 073a948
- parent
- c72c49c
- author
- Eric Bower
- date
- 2023-01-05 03:16:47 +0000 UTC
feat(imgs): return current total size for user storage This value will be displayed when uploading an image to imgs.sh. Example of what it looks like: `https://erock.imgs.sh/barefoot (space: 0.01/1.00GB, 1.39%)`
1 files changed,
+17,
-1
+17,
-1
1@@ -26,6 +26,10 @@ var GB = MB * 1024
2 var maxSize = 1 * GB
3 var maxImgSize = 10 * MB
4
5+func bytesToGB(size int) float32 {
6+ return (((float32(size) / 1024) / 1024) / 1024)
7+}
8+
9 type ctxUserKey struct{}
10
11 func getUser(s ssh.Session) (*db.User, error) {
12@@ -254,11 +258,23 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
13 return "", err
14 }
15
16+ totalFileSize, err := h.DBPool.FindTotalSizeForUser(user.ID)
17+ if err != nil {
18+ return "", err
19+ }
20+
21 curl := shared.NewCreateURL(h.Cfg)
22 url := h.Cfg.FullPostURL(
23 curl,
24 user.Name,
25 metadata.Slug,
26 )
27- return url, nil
28+ str := fmt.Sprintf(
29+ "%s (space: %.2f/%.2fGB, %.2f%%)",
30+ url,
31+ bytesToGB(totalFileSize),
32+ bytesToGB(maxSize),
33+ (float32(totalFileSize)/float32(maxSize))*100,
34+ )
35+ return str, nil
36 }