Repository navigation
setup 接口对齐 Zeta:状态接口、JSON 密钥、限流与管理员免密钥升级 - #127
Merged
todosdev[bot] merged 2 commits intoOct 18, 2026
Merged
Conversation
added 2 commits
October 18, 2026 14:40
Add GET /api/setup/state (public), a 405 for GET /api/setup/*, a JSON-body
POST /api/setup with a legacy X-Setup-Secret header fallback, and a keyless
POST /api/admin/setup for admins.
- Extract shared runMigrations() into lib/migrations-runner.ts, used by both
the setup and admin endpoints
- Return 500/400/403 for unconfigured/invalid/wrong secret (constant-time
comparison); rate-limit to 3 per IP per 10 min counted before the secret
check (429 + Retry-After)
- Mount setup at /api/setup, keep /setup as a backward-compatible alias
- Whitelist setup_page_enabled ('0'/'1') in admin settings; state defaults to
enabled when the setting is absent
- Add worker tests; update README/README.zh-CN/CLAUDE docs
Checkpoint: WzVRNGv2ju_UNM93bGHLI
Add two assertions so the backward-compatible /setup mount in index.ts is exercised: POST /setup with the X-Setup-Secret header returns 200, and GET /setup/* returns 405 + Allow: POST. Guards against silently breaking the alias in future changes. Checkpoint: fQy51T3T8GYCOUnLU97of
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.
Summary
runMigrations(),让POST /api/setup与新的POST /api/admin/setup走同一套迁移逻辑。Retry-After。Changes
接口(
apps/worker/src/routes/setup.ts)GET /api/setup/state(公开):返回{ enabled },只读setup_page_enabled('0'→ false,缺省/表不存在 → true),不泄露库初始化/schema 状态。GET /api/setup/*:返回 405 +Allow: POST,指引改用 JSON body。POST /api/setup:接受{"secret": "<SETUP_SECRET>"},body 为空时回退到旧X-Setup-Secret头;错误码 500(未配置)/400(body 非法)/403(密钥错误,常量时间比较);不因setup_page_enabled=0拒绝。迁移(
apps/worker/src/lib/migrations-runner.ts新增)runMigrations(env)抽出共享,保持TABLE_PREFIX前缀、createMigrationsTableSql、错误 break 语义,返回{ migrations: [...] }。管理端(
apps/worker/src/routes/admin.ts)POST /api/admin/setup:requireAdmin覆盖,免密钥走同一runMigrations,写run_setup审计日志(details 记 applied/skipped/error 数),不纳入 IP 限流。setup_page_enabled,仅接受'0'/'1'(非法 400),不做敏感值掩码。限流(
apps/worker/src/lib/kv.ts)checkSetupRateLimit改返回{ allowed, retryAfter },窗口 3 次/600s;fixedWindowIncrement拆出带retryAfter的详细版,原布尔版作为薄封装保留给登录/注册/忘记密码。挂载(
apps/worker/src/index.ts)/api/setup,保留/setup作为旧别名,旧curl POST /setup -H "X-Setup-Secret: ..."继续可用。测试与文档
apps/worker/test/setup.test.ts(state 三态、405、JSON/header、错误码、限流、admin 鉴权与审计、settings 白名单),D1Mock加applyMigrations=false以构造空库;覆盖/setup旧别名路径。README.md、README.zh-CN.md、CLAUDE.md的 setup 段落(JSON body、405、state、3 次/10 分钟、管理员按钮、setup_page_enabled只隐藏页面)。Testing
pnpm check(Biome)、pnpm typecheck、pnpm build全绿。pnpm test:61/61 通过(含新增 setup 测试)。