Skip to content

feat: R2 改為選填(截圖功能可選,無 R2 時優雅停用)#3

Merged
poterpan merged 10 commits into
mainfrom
feat/r2-optional
Jun 7, 2026
Merged

feat: R2 改為選填(截圖功能可選,無 R2 時優雅停用)#3
poterpan merged 10 commits into
mainfrom
feat/r2-optional

Conversation

@poterpan

@poterpan poterpan commented Jun 7, 2026

Copy link
Copy Markdown
Owner

背景

部分部署者不需要「成員上傳繳費截圖」,因此不想註冊 Cloudflare R2。本 PR 讓 R2 變成選填:未綁 R2 binding 時,截圖相關功能優雅停用,其餘(宣告繳費、後台審核、對帳、Discord 通知)全照常。

  • 設計 spec:docs/superpowers/specs/2026-06-07-r2-optional-design.md
  • 實作計畫:docs/superpowers/plans/2026-06-07-r2-optional.md

改了什麼

  • 偵測:以 !!env.BUCKET 判定(不另設開關);src/env.tsBUCKET 改選填,test/env.d.ts 覆寫為必填(測試環境一定有 R2,既有測試不受影響)。
  • 後端 4 處 guardsettleUserPeriod 無 R2 時跳過存截圖(has_proof=0);images 回 404;retention cron no-op;delete-proof 仍清 DB 欄位。
  • 偵測旗標GET /admin/workspacer2_configuredGET /upload/:tokenproof_enabled
  • 成員端:web 上傳頁依 proof_enabled 隱藏截圖欄位 + 調整文案;Discord /繳費 無 R2 時忽略附件並提示,宣告繳費照常。
  • 後台:未設定 R2 時跳一次性提示(localStorage),設定頁顯示常駐狀態列「截圖儲存(R2):未啟用」。
  • 文件/設定wrangler.toml[[r2_buckets]] 標註「選填」;DEPLOY.md §2 標 R2 為選填並說明停用功能。
  • 修正一個 API 一致性:/upload POST 回應的 has_proof 改用實際結算結果(無 R2 時正確回 0)。

驗證(CI 條件,無 .dev.vars)

  • pnpm -r typecheck
  • pnpm -r test170 passed (31 files) ✅(新增 settle/images/retention/admin/upload/Discord 等無-R2 行為測試 9 個)
  • pnpm -r build(web+admin)✅
  • 公開(已追蹤)檔 owner 值掃描:全乾淨

流程

每個 Task 經 implementer → spec 合規審查 → 程式品質審查(含修正迴圈),最後整體 review。wrangler.toml(skip-worktree 保護 owner 真實值)的選填註解由 controller 以安全程序處理,未外洩真實值。

🤖 Generated with Claude Code

poterpan added 10 commits June 7, 2026 20:47
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.
@poterpan poterpan merged commit 25a6b4c into main Jun 7, 2026
2 checks passed
@poterpan poterpan deleted the feat/r2-optional branch June 7, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant