Repository navigation
ONE-422: 后端 setup 三件套端点 + setup 页面开关存储(ONE-424) - #7
Merged
Merged
Conversation
- GET /api/setup/state(新规范名,无鉴权、no-store、{enabled, ownerExists, tablePrefix}),
GET /api/setup/status 改为同逻辑同载荷的兼容别名
- POST /api/setup:X-Setup-Secret 常量时间校验,按 IP 每 10 分钟 3 次(复用 login_attempts,
未初始化库退化为单 isolate 内存窗口),只跑账本迁移,成功 200 与 409 冲突形状固定
- 管理面三端点(adminRoutes 会话鉴权):POST /api/admin/setup(免密钥,形状与密钥端点一致)、
GET /api/admin/system(tablePrefix/setupPageEnabled/ledger)、
PUT /api/admin/system/setup-page(严格布尔校验)
- POST /api/auth/setup:契约不变,仅所有者建成后写入 {prefix}settings.setup_page_enabled='0'
(单人站默认关;开关只门控页面,不门控两个密钥接口)
- setup_page_enabled 不进站点设置白名单 / SiteSettingsDto / /api/public
- 复核 Workers Static Assets SPA 回退对 /setup 直接访问可达(既有 app.get("*") 即可)
- 新增 worker/test/setup.test.ts(18 例):状态语义、别名、密钥/限流、409 冲突双端点一致、
admin 三端点 401、开关持久化与泄露检查、/setup 回退
- docs/api-contract.md、README 同步新契约
This was referenced Nov 5, 2026
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.
关联父单 ONE-422 · 子单 ONE-424(Stage 1 · 后端实现)。规格:SETUP-PAGE-SPEC v1.0 §3(+ §8 后端侧各点)。
改了什么
worker/src/routes/setup.ts(新)GET /api/setup/state、GET /api/setup/status(同逻辑别名)、POST /api/setupworker/src/services/setup.ts(新)setup_page_enabled读写、共享迁移执行器(两端点同形)worker/src/core/setup-rate-limit.ts(新)worker/src/routes/admin.tsPOST /api/admin/setup、GET /api/admin/system、PUT /api/admin/system/setup-page(均在既有adminRoutes会话鉴权下)worker/src/routes/auth.tsPOST /api/auth/setup契约不变,仅所有者建成后写入{prefix}settings.setup_page_enabled = '0'worker/src/index.tssetupRoutes(/api/setup/status旧实现移走,改由别名承载)worker/src/lib/migrations-runner.tslistRecordedMigrations()(账本已记录迁移名,缺账本返回[])worker/src/types.tsSetupStateDto/SetupMigrationDto/SetupResultDto/AdminSystemDtoworker/test/setup.test.ts(新)docs/api-contract.md、README.md契约要点(按子单冻结口径实现)
GET /api/setup/state:无鉴权、Cache-Control: no-store、{enabled, ownerExists, tablePrefix},无密钥/哈希。ownerExists={prefix}users行数 > 0,表不存在按false。enabled:未初始化恒true;已初始化只有'1'为开(无此键 → 关)。POST /api/setup:X-Setup-Secret走safeEqual;密钥缺失/占位符 → 500server misconfigured,不匹配 → 403;IP 每 10 分钟 3 次,超限 429(带Retry-After)。只跑applyMigrations():不建用户、不改密码、不删表。成功 200{success, tablePrefix, migrations, ownerExists};前缀冲突 409{error:"table prefix conflict", detail}。POST /api/admin/setup:免密钥,响应与 409 形状与上面完全一致(单测用toEqual对拍)。GET /api/admin/system→{tablePrefix, setupPageEnabled, ledger};PUT /api/admin/system/setup-page严格布尔校验(非布尔 400)。setup_page_enabled不进站点设置白名单 /SiteSettingsDto//api/public;开关只门控页面,不门控两个密钥接口。实现说明(依赖 vs 自研)
applyMigrations),不改schema_v1、不新增迁移。{prefix}login_attempts存储(行 key 用保留命名空间__setup_rate__:<ip>,USERNAME_RE不允许:故不可能撞真实账号),未初始化库尚无该表时退化为单 isolate 内存窗口 —— 这样「未初始化库 + 错密钥 4 次 → 429」这条验收才成立,且不新增表/迁移、不引框架。app.get("*")(404 → 重取/)对/setup直接访问/刷新可达,无需改后端(见单测serves index.html for a direct /setup request)。自测
新增用例覆盖:状态三态语义与别名一致、403/429(含不同 IP 独立预算)、空库升级不建号、已初始化库全
skipped且不发会话、admin 三端点未登录 401、开关持久化与/api/setup/state联动、严格布尔 400、setup_page_enabled泄露检查、前缀冲突双端点同detail且库中不出现第二套表、/setupSPA 回退。迁移与回滚
{prefix}settings的一个键)。回滚=revert 本 PR;已有setup_page_enabled行是惰性键,回滚后无副作用。交给前端(ONE-425 口径)
SPA 请改调
GET /api/setup/state(/api/setup/status仍保留为兼容别名,同载荷)。管理面系统管理区所需端点即上表三个 admin 端点,字段名见worker/src/types.ts的SetupStateDto/SetupResultDto/AdminSystemDto。