Skip to content

feat: view shared links at /log behind cloudflare access - #12

Merged
musingfox merged 4 commits into
mainfrom
feat/shared-link-log-page
Oct 16, 2026
Merged

musingfox merged 4 commits into
mainfrom
feat/shared-link-log-page

Conversation

@musingfox

@musingfox musingfox commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Adds a page for reading the optional shared-link log, so the owner of a deployment can see the links that GET /?url= produced.

Behaviour

  • Only with the log enabled. /log is served only when the SHARED_LINKS binding exists; otherwise it falls through to the share-link route and answers 404, as before.
  • Only behind Cloudflare Access. Without ctx.access the page answers 403 and never touches KV. The Worker does not verify JWTs itself; it relies on the runtime-provided ctx.access. Access must protect only the /log path, because protecting the whole Worker would also block share links and /media/.
  • One list per view. ?day=YYYY-MM-DD (default: today, UTC) becomes the key prefix. The free plan writes at most 1,000 keys a day and one list returns up to 1,000 keys, so a day fits in one call; list requests are capped at 1,000 a day on the free plan, so there is no cross-day paging or search. An invalid day answers 400 before listing.
  • Records are newest first, read from key metadata only (no per-key get). URLs are HTML-escaped. Responses carry Cache-Control: no-store, X-Robots-Tag: noindex and Referrer-Policy: no-referrer. A failing list answers 503.

Specs

  • New: docs/spec/shared-link-log-page-behind-access.md, verified by test/shared-link-log-page-behind-access.test.ts. Six deliberate mutations (no Access check, no escaping, no no-store, no newest-first, no day round-trip check, no 503) each turned a test red.

Verification

  • bun run check passes: 586 tests, typecheck clean.
  • cf dev locally: /log answers 403 with LOG_SHARED_LINKS=1 and 404 without it.
  • Not yet verified: the 200 path with a real Access login. The docs do not say whether a path-scoped self-hosted Access application populates ctx.access; check after deploying with Access on /log.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 新功能
    • 新增共享連結日誌頁面,可依 UTC 日期瀏覽紀錄,並按時間由新到舊排列;提供前後日期導覽及原始網址、分享連結。
    • 日誌頁面僅限通過 Cloudflare Access 驗證的請求使用;未授權、日期無效或日誌讀取失敗時,會顯示相應錯誤。
  • 文件
    • 新增日誌端點與部署設定說明,提醒僅保護 /log 路徑,避免影響共享連結及媒體功能。

musingfox and others added 4 commits October 16, 2026 15:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cess

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: musingfox/better-link/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccc9e698-ff8e-42a4-93f3-93bdbf62d277
📥 Commits

Reviewing files that changed from the base of the PR and between 54553a5 and a95a42a.

📒 Files selected for processing: 9
  • ARCHITECTURE.md
  • README.md
  • README.zh-TW.md
  • docs/spec/shared-link-log-page-behind-access.md
  • docs/spec/shared-links-logged-to-kv-at-conversion.md
  • src/index.ts
  • src/shared-link-log-page.ts
  • test/shared-link-log-page-behind-access.test.ts
  • test/support/fake-kv.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

新增受 Cloudflare Access 保護的 /log 頁面。頁面依指定或預設的 UTC 日期列取並呈現共享連結日誌。Worker 在日誌 binding 存在時將請求導向此頁面,並新增相關規格與部署文件。

Changes: 共享連結日誌頁面

Layer / File(s) Summary
日誌頁面與資料列取
src/shared-link-log-page.ts, test/shared-link-log-page-behind-access.test.ts, test/support/fake-kv.ts
頁面檢查 Access 與 KV binding,驗證日期,依 UTC 日期前綴列取日誌並呈現 HTML。錯誤分別回應 403、404、400 或 503。測試涵蓋存取、日期、呈現、標頭與 KV 錯誤。
Worker 路由與端點文件
src/index.ts, ARCHITECTURE.md, README.md, README.zh-TW.md, docs/spec/shared-link-log-page-behind-access.md, docs/spec/shared-links-logged-to-kv-at-conversion.md
Worker 在日誌 binding 存在時將 /log 導向頁面;否則沿用既有 shareRedirect 路徑。文件新增端點行為、Access 設定及相關規格連結。

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant Worker
  participant sharedLinkLogPage
  participant ExecutionContext
  participant SHARED_LINKS
  Browser->>Worker: GET /log
  Worker->>Worker: 檢查 hasSharedLinkLog(env)
  Worker->>sharedLinkLogPage: binding 存在時呼叫頁面處理器
  sharedLinkLogPage->>ExecutionContext: 讀取 ctx.access
  ExecutionContext-->>sharedLinkLogPage: Access 狀態
  sharedLinkLogPage->>SHARED_LINKS: 以 UTC 日期前綴呼叫 list
  SHARED_LINKS-->>sharedLinkLogPage: 日誌鍵與 metadata
  sharedLinkLogPage-->>Browser: HTML 或錯誤回應
Loading
Merge Risk: ⚪ Minimal · up to a95a4

The log page is ready to merge after normal checks. Its documented daily limit does not require pagination.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. (5 skipped: 5… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 標題清楚描述主要變更:新增受 Cloudflare Access 保護的 /log 共享連結檢視頁面。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. (5 skipped: 5 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@musingfox
musingfox merged commit efc05ee into main Oct 16, 2026
2 checks passed
@musingfox
musingfox deleted the feat/shared-link-log-page branch October 16, 2026 08:17
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