repos / pico

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

commit
b702df1
parent
d812172
author
Eric Bower
date
2024-01-25 20:49:32 +0000 UTC
fix: default size limit fallbacks
4 files changed,  +24, -0
M db/db.go
+14, -0
 1@@ -168,6 +168,20 @@ func NewFeatureFlag(userID, name string, storageMax uint64, fileMax int64) *Feat
 2 	}
 3 }
 4 
 5+func (ff *FeatureFlag) FindStorageMax(defaultSize uint64) uint64 {
 6+	if ff.Data.StorageMax == 0 {
 7+		return defaultSize
 8+	}
 9+	return ff.Data.StorageMax
10+}
11+
12+func (ff *FeatureFlag) FindFileMax(defaultSize int64) int64 {
13+	if ff.Data.FileMax == 0 {
14+		return defaultSize
15+	}
16+	return ff.Data.FileMax
17+}
18+
19 func (ff *FeatureFlag) IsValid() bool {
20 	if ff.ExpiresAt.IsZero() {
21 		return false
M filehandlers/assets/handler.go
+4, -0
 1@@ -200,6 +200,10 @@ func (h *UploadAssetHandler) Validate(s ssh.Session) error {
 2 			h.Cfg.MaxAssetSize,
 3 		)
 4 	}
 5+	// this is jank
 6+	ff.Data.StorageMax = ff.FindStorageMax(h.Cfg.MaxSize)
 7+	ff.Data.FileMax = ff.FindFileMax(h.Cfg.MaxAssetSize)
 8+
 9 	s.Context().SetValue(ctxFeatureFlagKey{}, ff)
10 
11 	assetBucket := shared.GetAssetBucketName(user.ID)
M filehandlers/imgs/handler.go
+4, -0
 1@@ -196,6 +196,10 @@ func (h *UploadImgHandler) Validate(s ssh.Session) error {
 2 			h.Cfg.MaxAssetSize,
 3 		)
 4 	}
 5+	// this is jank
 6+	ff.Data.StorageMax = ff.FindStorageMax(h.Cfg.MaxSize)
 7+	ff.Data.FileMax = ff.FindFileMax(h.Cfg.MaxAssetSize)
 8+
 9 	s.Context().SetValue(ctxFeatureFlagKey{}, ff)
10 
11 	s.Context().SetValue(ctxUserKey{}, user)
M pgs/cli.go
+2, -0
1@@ -148,6 +148,8 @@ func (c *Cmd) stats(cfgMaxSize uint64) error {
2 	if err != nil {
3 		ff = db.NewFeatureFlag(c.User.ID, "pgs", cfgMaxSize, 0)
4 	}
5+	// this is jank
6+	ff.Data.StorageMax = ff.FindStorageMax(cfgMaxSize)
7 	storageMax := ff.Data.StorageMax
8 
9 	bucketName := shared.GetAssetBucketName(c.User.ID)