Commit e5d5430

Eric Bower  ·  2026-08-11 13:56:36 -0400 EDT
parent 06944c5
refactor(pgs): validate pico+ before uploading so we don't create empty projects
3 files changed,  +28, -12
+1, -0
......@@ -194,6 +194,7 @@ services:
194194 environment:
195195 APP_DOMAIN: ${PGS_DOMAIN:-pgs.sh}
196196 APP_EMAIL: ${PGS_EMAIL:-hello@pico.sh}
197+ DATABASE_URL: ${DATABASE_URL}
197198 volumes:
198199 - ${PGS_CADDYFILE}:/etc/caddy/Caddyfile
199200 - ./data/pgs-caddy/data:/data
+24, -10
......@@ -27,6 +27,7 @@ import (
2727 type ctxBucketKey struct{}
2828 type ctxStorageSizeKey struct{}
2929 type ctxProjectKey struct{}
30+type ctxFeatureFlagKey struct{}
3031 type ctxDenylistKey struct{}
3132
3233 type DenyList struct {
......@@ -59,6 +60,19 @@ func setProject(s *pssh.SSHServerConnSession, project *db.Project) {
5960 s.SetValue(ctxProjectKey{}, project)
6061 }
6162
63+func getFeatureFlag(s *pssh.SSHServerConnSession) *db.FeatureFlag {
64+ v := s.Context().Value(ctxFeatureFlagKey{})
65+ if v == nil {
66+ return nil
67+ }
68+ ff := s.Context().Value(ctxFeatureFlagKey{}).(*db.FeatureFlag)
69+ return ff
70+}
71+
72+func setFeatureFlag(s *pssh.SSHServerConnSession, ff *db.FeatureFlag) {
73+ s.SetValue(ctxFeatureFlagKey{}, ff)
74+}
75+
6276 func getBucket(s *pssh.SSHServerConnSession) (storage.Bucket, error) {
6377 bucket := s.Context().Value(ctxBucketKey{}).(storage.Bucket)
6478 if bucket.Name == "" {
......@@ -205,19 +219,23 @@ func (h *UploadAssetHandler) Validate(s *pssh.SSHServerConnSession) error {
205219 return err
206220 }
207221
222+ ff, err := findPlusFF(h.Cfg.DB, h.Cfg, user.ID)
223+ if err != nil {
224+ return err
225+ }
226+ setFeatureFlag(s, ff)
227+
208228 assetBucket := shared.GetAssetBucketName(user.ID)
209229 bucket, err := h.Cfg.Storage.UpsertBucket(assetBucket)
210230 if err != nil {
211231 return err
212232 }
213-
214233 s.SetValue(ctxBucketKey{}, bucket)
215234
216235 totalStorageSize, err := h.Cfg.Storage.GetBucketQuota(bucket)
217236 if err != nil {
218237 return err
219238 }
220-
221239 s.SetValue(ctxStorageSizeKey{}, totalStorageSize)
222240
223241 logger.Info(
......@@ -337,14 +355,6 @@ func (h *UploadAssetHandler) Write(s *pssh.SSHServerConnSession, entry *sendutil
337355 return "", err
338356 }
339357
340- featureFlag, err := findPlusFF(h.Cfg.DB, h.Cfg, user.ID)
341- if err != nil {
342- return "", err
343- }
344- if !featureFlag.IsValid() && pgsdb.IsProjectPrivate(projectName) {
345- return "", fmt.Errorf("private projects are only allowed for pico+ users")
346- }
347-
348358 // calculate the filsize difference between the same file already
349359 // stored and the updated file being uploaded
350360 assetFilename := shared.GetAssetFileName(entry)
......@@ -383,6 +393,10 @@ func (h *UploadAssetHandler) Write(s *pssh.SSHServerConnSession, entry *sendutil
383393 return "", err
384394 }
385395
396+ featureFlag := getFeatureFlag(s)
397+ if featureFlag == nil {
398+ return "", fmt.Errorf("pico+ feature flag ctx not set")
399+ }
386400 // SFTP does not report file size so the more performant way to
387401 // check filesize constraints is to try and upload the file to s3
388402 // with a specialized reader that raises an error if the filesize limit
+3, -2
......@@ -186,7 +186,6 @@ func (m *ServicesList) getServiceKv() []Kv {
186186 {"prose", "active"},
187187 {"pipe", "active"},
188188 {"pastes", "active"},
189- {"rss-to-email", "active"},
190189 }
191190
192191 if hasPlus {
......@@ -195,13 +194,15 @@ func (m *ServicesList) getServiceKv() []Kv {
195194 []string{"pages", "active"},
196195 []string{"tuns", "active"},
197196 []string{"irc bouncer", "active"},
197+ []string{"rss-to-email", "active"},
198198 )
199199 } else {
200200 data = append(
201201 data,
202- []string{"pages", "free tier"},
202+ []string{"pages", "pico+"},
203203 []string{"tuns", "pico+"},
204204 []string{"irc bouncer", "pico+"},
205+ []string{"rss-to-email", "pico+"},
205206 )
206207 }
207208