- commit
- bbb4d7c
- parent
- e88909e
- author
- Eric Bower
- date
- 2022-10-09 01:16:56 +0000 UTC
feat(imgs): set img file size limit to 10mb
3 files changed,
+10,
-4
+1,
-0
1@@ -24,6 +24,7 @@ var KB = 1024
2 var MB = KB * 1024
3 var GB = MB * 1024
4 var maxSize = 1 * GB
5+var maxImgSize = 10 * MB
6
7 type PostMetaData struct {
8 *db.Post
+8,
-3
1@@ -11,12 +11,17 @@ import (
2 )
3
4 func (h *UploadImgHandler) validateImg(data *PostMetaData) (bool, error) {
5- fileSize, err := h.DBPool.FindTotalSizeForUser(data.User.ID)
6+ totalFileSize, err := h.DBPool.FindTotalSizeForUser(data.User.ID)
7 if err != nil {
8 return false, err
9 }
10- if fileSize+data.FileSize > maxSize {
11- return false, fmt.Errorf("ERROR: user (%s) has exceeded (%d) max (%d)", data.User.Name, fileSize, maxSize)
12+
13+ if data.FileSize > maxImgSize {
14+ return false, fmt.Errorf("ERROR: file (%s) has exceeded maximum file size (%d bytes)", data.Filename, maxImgSize)
15+ }
16+
17+ if totalFileSize+data.FileSize > maxSize {
18+ return false, fmt.Errorf("ERROR: user (%s) has exceeded (%d bytes) max (%d bytes)", data.User.Name, totalFileSize, maxSize)
19 }
20
21 if !shared.IsExtAllowed(data.Filename, h.Cfg.AllowedExt) {
+1,
-1
1@@ -50,7 +50,7 @@
2 <li>Hotlinking encouraged!</li>
3 <li>No javascript</li>
4 <li>No ads</li>
5- <li>No file size limits</li>
6+ <li>10MB max image size</li>
7 <li>1GB max storage</li>
8 </ul>
9 </section>