Skip to content

前端:新增 /setup 初始化页面与后台「检查并升级数据库」入口 - #128

Merged
todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a14dd3-41b6-7379-a826-7a586fb8e212
Oct 18, 2026
Merged

todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a14dd3-41b6-7379-a826-7a586fb8e212

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a public /setup initialization page matching the Zeta setup flow: reads GET /api/setup/state, shows a secret form when enabled (or a "disabled" notice), and displays per-migration results from POST /api/setup.
  • Adds an admin "Check & Upgrade Database" action plus a setup_page_enabled toggle in the admin settings page.
  • Localizes every setup string (en + zh-CN) and maps setup/upgrade errors by HTTP status code through the existing apiErrorCodes mechanism.

Changes

  • Routing (apps/web/src/App.tsx): new lazy /setup route in the public section, ahead of the * fallback.
  • API client (apps/web/src/api/client.ts): SetupMigration/SetupResult types; setupApi.state() / setupApi.run(secret) and adminApi.runSetup(); ApiRequestError now surfaces retryAfter parsed from the Retry-After header (backward compatible).
  • Public page (apps/web/src/pages/SetupPage.tsx): fetches state on mount, handles loading / 404 ("backend has not provided this endpoint yet") / disabled, renders a password-typed secret input (no echo), and shows migration results; submit button disables while running.
  • Shared result list (apps/web/src/components/setup-migrations.tsx): renders each migration's name + status badge (applied/skipped/error), with inline error text for failures — reused by both the public page and the admin action.
  • Admin settings (apps/web/src/pages/admin/AdminSettingsPage.tsx): setup_page_enabled toggle (stored '0'/'1', defaults on, "only hides the page" copy) and a "Check & Upgrade Database" button calling POST /api/admin/setup with loading state and inline results/errors.
  • Error mapping (apps/web/src/lib/setup.ts): pure resolveSetupError maps 400/403/404/429 (with Retry-After seconds)/500 and known backend codes to i18n keys; session-expired returns null (silent, AuthProvider shows the single global toast); unknown errors fall back to a generic key. Also holds migrationStatusLabel / MIGRATION_STATUS_VARIANT display mappings and formatSetupError.
  • i18n (apps/web/src/i18n/locales/en.ts, zh-CN.ts): full setup.*, admin.setupPage*, admin.runSetup*, and toast.setupPage* strings in both locales; no hardcoded Chinese.
  • Tests (apps/web/src/lib/setup.test.ts, apps/web/package.json): node --test coverage for state, submit success, 429 Retry-After, admin upgrade success, error mapping (incl. session expiry + generic fallback), status label/variant display mapping, and locale completeness.

Testing

  • pnpm check (Biome), pnpm typecheck, pnpm build, and pnpm test all pass — 44 tests green. Tests follow the existing node --test + stubbed-fetch style (no React renderer), so the display logic is exercised through its extracted pure functions; the components themselves are validated by the typecheck + Vite production build.

Todos added 2 commits October 18, 2026 15:12
- Add public /setup page (state check, secret form, migration results)
- Add setup_page_enabled toggle and "check & upgrade" button to admin settings
- Surface Retry-After on ApiRequestError and map setup errors by status code
- Add setupApi/adminApi.runSetup to the typed client plus en/zh-CN strings
- Cover state, submit success, 429 and admin upgrade in node --test

Checkpoint: T89ynSWY-zOYYWExTx-dD
- Return null for session-expired setup/admin errors instead of leaking
  untranslated text alongside AuthProvider's global toast
- Fall back to setup.errorGeneric for unclassified errors, dropping the raw
  backend-message branch that bypassed i18n
- Extract migration status label/variant and formatSetupError into pure
  helpers and cover them (plus session-expiry and interpolation) in node --test

Checkpoint: kWYiOxJIc96_8plsowQ7v
@todosdev
todosdev Bot merged commit 9b483b5 into main Oct 18, 2026
4 checks passed
@mapxn
mapxn deleted the tds/conv-01a14dd3-41b6-7379-a826-7a586fb8e212 branch October 18, 2026 08:56
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.

0 participants