feat: R2 改為選填(截圖功能可選,無 R2 時優雅停用)#3
Merged
Merged
Conversation
Make Cloudflare R2 optional: detect via binding presence (!!env.BUCKET), guard the 4 R2 usage points so screenshot capture/view/retention degrade gracefully while payment declaration/verification/reconcile stay intact. Backend reports r2_configured / proof_enabled; admin shows a one-time localStorage prompt + a persistent status row. Decisions captured from brainstorming.
5 tasks (TDD): backend BUCKET-optional + guards + detection flags; Discord screenshot ignore; web hide-screenshot; admin one-time notice + status row; DEPLOY.md. wrangler.toml comment deferred to a controller-only skip-worktree step to avoid leaking owner values.
BUCKET becomes an optional binding; settle skips proof storage (has_proof=0), images 404, retention no-ops, delete-proof still clears the DB column when R2 is absent. /admin/workspace reports r2_configured and /upload/:token reports proof_enabled. Test env overrides BUCKET as required so existing tests are unaffected.
…ured Skip the attachment download when there's no R2 and tell the member to use channel/ note (or append a note on success). The core storage guard already drops the proof; this avoids a wasted download and gives clear feedback.
The upload page reads proof_enabled from the token info and hides the screenshot field + adjusts the helper copy when R2 is not configured; channel/note still work.
When the worker reports r2_configured=false, show a one-time (localStorage) modal listing the disabled screenshot features, and a persistent status row in Settings.
Document that skipping R2 (omit the [[r2_buckets]] binding) runs the system without screenshot upload/view/retention; everything else works. Note the admin one-time prompt + the persistent status row.
R2 is optional — removing the binding runs the system without screenshot upload/view/retention; everything else works.
When R2 is absent the posted file is dropped (has_proof=0 in D1); the POST response must reflect that instead of echoing the input. Use r.screenshotKey.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
部分部署者不需要「成員上傳繳費截圖」,因此不想註冊 Cloudflare R2。本 PR 讓 R2 變成選填:未綁 R2 binding 時,截圖相關功能優雅停用,其餘(宣告繳費、後台審核、對帳、Discord 通知)全照常。
docs/superpowers/specs/2026-06-07-r2-optional-design.mddocs/superpowers/plans/2026-06-07-r2-optional.md改了什麼
!!env.BUCKET判定(不另設開關);src/env.ts的BUCKET改選填,test/env.d.ts覆寫為必填(測試環境一定有 R2,既有測試不受影響)。settleUserPeriod無 R2 時跳過存截圖(has_proof=0);images回 404;retentioncron no-op;delete-proof仍清 DB 欄位。GET /admin/workspace回r2_configured;GET /upload/:token回proof_enabled。proof_enabled隱藏截圖欄位 + 調整文案;Discord/繳費無 R2 時忽略附件並提示,宣告繳費照常。wrangler.toml的[[r2_buckets]]標註「選填」;DEPLOY.md§2 標 R2 為選填並說明停用功能。/uploadPOST 回應的has_proof改用實際結算結果(無 R2 時正確回 0)。驗證(CI 條件,無 .dev.vars)
pnpm -r typecheck✅pnpm -r test→ 170 passed (31 files) ✅(新增 settle/images/retention/admin/upload/Discord 等無-R2 行為測試 9 個)pnpm -r build(web+admin)✅流程
每個 Task 經 implementer → spec 合規審查 → 程式品質審查(含修正迴圈),最後整體 review。
wrangler.toml(skip-worktree 保護 owner 真實值)的選填註解由 controller 以安全程序處理,未外洩真實值。🤖 Generated with Claude Code