From 99c96975c52af833b1253a113a4c384cb290f0a4 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:19:42 +0800 Subject: [PATCH] refactor(web): rename admin maintenance tab and route to others - rename maintenance-section to others-section - update route slug from database to others without legacy redirects - update i18n keys from admin.maintenance to admin.others - update routing, page title mapping, docs, and unit tests --- README.md | 4 +- web/src/App.test.tsx | 19 ++++-- web/src/App.tsx | 10 +-- web/src/hooks/use-page-title.ts | 3 +- web/src/locales/en.json | 6 +- web/src/locales/zh.json | 6 +- web/src/pages/admin.test.tsx | 67 ++++++++++++++++--- web/src/pages/admin/admin-page.tsx | 15 ++--- ...tenance-section.tsx => others-section.tsx} | 12 ++-- 9 files changed, 92 insertions(+), 50 deletions(-) rename web/src/pages/admin/{maintenance-section.tsx => others-section.tsx} (86%) diff --git a/README.md b/README.md index 63473b7..3de0ef0 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Cbox 是多租户临时文件中转站:登录用户管理自己的文件夹与 - **文件过期与改期**:上传时用户可选预设时长(永不过期 / 1 小时 / 24 小时 / 7 天 / 30 天);支持上传后随时修改过期档位;到期后本人下载与外部分享一律 404;定时任务自动回收物理对象并释放容量配额。 - **公开免密直链分享**:针对单个文件生成高熵令牌公开分享直链(`/s/`);直链免登录直接流式下载文件本体,无中间页与密码环节;创建直链自动封顶文件到期时间,详情显示下载计数、最近下载时间,可随时撤销。 - **双限额分层管理**:总容量上限与单文件大小双重限额;默认全局 100 MiB,管理员可在系统管理动态调整;支持管理员针对指定用户设置独立限额覆盖,覆盖优先、逐项独立回落;生效上限受平台硬顶自动约束。 -- **系统管理**:全局文件限额配置、邮件通道配置(SMTP / Resend)与测试邮件发送、注册与审核策略开关、用户管理(全量用户列表、单人限额覆盖弹窗、行内审核批准 / 拒绝、操作菜单重置密码 / 封禁 / 提权 / 删除)、数据库维护(setup 页开关与生效表前缀展示)。 +- **系统管理**:全局文件限额配置、邮件通道配置(SMTP / Resend)与测试邮件发送、注册与审核策略开关、用户管理(全量用户列表、单人限额覆盖弹窗、行内审核批准 / 拒绝、操作菜单重置密码 / 封禁 / 提权 / 删除)、其他(setup 页开关与生效表前缀展示)。 - **定时任务与 waker**:`[triggers] crons` 提供原生定时入口;每小时执行定时清理轮次:清理已过期文件(物理删除 R2 对象与元数据)、清理独立过期分享、对账清理超过 24 小时无 D1 记录的 R2 孤儿对象;接入 waker 仅需一把 `WAKER_SIGNING_KEY` Secret(未配走 Cron、配了 waker 验签接管),不设多余模式开关。 - **CI/CD 流水线**:`ci.yml`(lint / format / typecheck / build / test / 身份校验 / 部署 dry-run)、`deploy.yml`(push main 自动部署)、`tag.yml`(手动打语义化版本 tag)、`release.yml`(tag 触发 GitHub Release)。 @@ -121,7 +121,7 @@ openssl rand -base64 32 # SIGNING_SECRET 1. 打开 `/setup`,输入 `.dev.vars` 里的 `SETUP_SECRET`,点「初始化」:跑迁移,回显生效表前缀与迁移记录。 2. 点「注册首个用户」(或打开 `/register`)建账号:首个用户自动成为管理员并直接批准。 -3. 之后 setup 页默认关闭;管理员可在「系统管理 → 数据库维护」重开页面。后续数据库升级由部署流水线自动调用 `POST /api/setup` 执行增量迁移;`POST /api/setup` 纯升级端点只跑迁移,不会建用户、改密码或删数据。 +3. 之后 setup 页默认关闭;管理员可在「系统管理 → 其他」重开页面。后续数据库升级由部署流水线自动调用 `POST /api/setup` 执行增量迁移;`POST /api/setup` 纯升级端点只跑迁移,不会建用户、改密码或删数据。 初始化也可以直接用 curl(把 `` 换成 `.dev.vars` 里的值,密钥只放请求头): diff --git a/web/src/App.test.tsx b/web/src/App.test.tsx index 086a57b..f87fcc4 100644 --- a/web/src/App.test.tsx +++ b/web/src/App.test.tsx @@ -406,17 +406,25 @@ describe("路由与根门", () => { ).toBeInTheDocument() u4() - const { unmount: u5 } = renderAt(routes, "/admin/database") + // 5. /admin/others 独立 URL 直达 + const { unmount: u5 } = renderAt(routes, "/admin/others") expect( - await screen.findByRole("heading", { name: "数据库维护" }) + await screen.findByRole("heading", { name: "其他" }) ).toBeInTheDocument() u5() - const { unmount: u6 } = renderAt(routes, "/admin/maintenance") + // 6. 旧路径 /admin/database 与 /admin/maintenance 不留重定向,回落至首 tab /admin/email + const { unmount: u6 } = renderAt(routes, "/admin/database") expect( - await screen.findByRole("heading", { name: "数据库维护" }) + await screen.findByRole("heading", { name: "邮件配置" }) ).toBeInTheDocument() u6() + + const { unmount: u7 } = renderAt(routes, "/admin/maintenance") + expect( + await screen.findByRole("heading", { name: "邮件配置" }) + ).toBeInTheDocument() + u7() }) it("页面标题映射支持 /admin/* 与 /settings/* 子路径", () => { @@ -424,8 +432,7 @@ describe("路由与根门", () => { expect(titleKeyFor("/admin/email")).toBe("workbench.nav.admin") expect(titleKeyFor("/admin/registration")).toBe("workbench.nav.admin") expect(titleKeyFor("/admin/users")).toBe("workbench.nav.admin") - expect(titleKeyFor("/admin/database")).toBe("workbench.nav.admin") - expect(titleKeyFor("/admin/maintenance")).toBe("workbench.nav.admin") + expect(titleKeyFor("/admin/others")).toBe("workbench.nav.admin") expect(titleKeyFor("/admin/other-subpath")).toBe("workbench.nav.admin") expect(titleKeyFor("/settings")).toBe("settings.title") diff --git a/web/src/App.tsx b/web/src/App.tsx index e8a003d..b8dca59 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -22,7 +22,7 @@ import { } from "@/pages/admin/admin-page" import { EmailSection } from "@/pages/admin/email-section" import { FileLimitsSection } from "@/pages/admin/file-limits-section" -import { MaintenanceSection } from "@/pages/admin/maintenance-section" +import { OthersSection } from "@/pages/admin/others-section" import { RegistrationSection } from "@/pages/admin/registration-section" import { ForgotPasswordPage } from "@/pages/auth/forgot-password" import { LoginPage } from "@/pages/auth/login" @@ -99,12 +99,8 @@ export const routes: RouteObject[] = [ { path: "users", element: }, { path: "limits", element: }, { - path: "database", - element: - }, - { - path: "maintenance", - element: + path: "others", + element: }, { path: "*", diff --git a/web/src/hooks/use-page-title.ts b/web/src/hooks/use-page-title.ts index 3dc6e60..c8a469e 100644 --- a/web/src/hooks/use-page-title.ts +++ b/web/src/hooks/use-page-title.ts @@ -20,8 +20,7 @@ export const PAGE_TITLE_KEYS: Record = { "/admin/email": "workbench.nav.admin", "/admin/registration": "workbench.nav.admin", "/admin/users": "workbench.nav.admin", - "/admin/database": "workbench.nav.admin", - "/admin/maintenance": "workbench.nav.admin" + "/admin/others": "workbench.nav.admin" } export function titleKeyFor(pathname: string): string { diff --git a/web/src/locales/en.json b/web/src/locales/en.json index d400957..45ed6e8 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -382,7 +382,7 @@ "registration": "Registration & Approval", "users": "Users", "limits": "File Limits", - "maintenance": "Database Maintenance" + "others": "Others" }, "limits": { "title": "File Limits (Global)", @@ -494,8 +494,8 @@ "copyFailed": "Copy failed — select the password and copy it manually" } }, - "maintenance": { - "title": "Database", + "others": { + "title": "Others", "setupPage": "Open the setup page", "setupPageHint": "This only gates the page; the endpoint still requires the deployment secret.", "tablePrefix": "Effective table prefix" diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index d7c6bb2..834f341 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -382,7 +382,7 @@ "registration": "注册与审核", "users": "用户管理", "limits": "文件限额", - "maintenance": "数据库维护" + "others": "其他" }, "limits": { "title": "文件限额(全局)", @@ -494,8 +494,8 @@ "copyFailed": "复制失败,请手动选中密码复制" } }, - "maintenance": { - "title": "数据库维护", + "others": { + "title": "其他", "setupPage": "开放初始化页面", "setupPageHint": "只控制页面入口,接口仍需部署密钥。", "tablePrefix": "生效表前缀" diff --git a/web/src/pages/admin.test.tsx b/web/src/pages/admin.test.tsx index ec72b8a..6c93093 100644 --- a/web/src/pages/admin.test.tsx +++ b/web/src/pages/admin.test.tsx @@ -22,7 +22,7 @@ import { } from "@/pages/admin/admin-page" import { EmailSection } from "@/pages/admin/email-section" import { FileLimitsSection } from "@/pages/admin/file-limits-section" -import { MaintenanceSection } from "@/pages/admin/maintenance-section" +import { OthersSection } from "@/pages/admin/others-section" import { RegistrationSection } from "@/pages/admin/registration-section" import { useAuthStore } from "@/stores/auth" @@ -63,11 +63,7 @@ const adminRoutes: RouteObject[] = [ { path: "registration", element: }, { path: "users", element: }, { path: "limits", element: }, - { path: "database", element: }, - { - path: "maintenance", - element: - }, + { path: "others", element: }, { path: "*", element: } ] } @@ -305,6 +301,37 @@ describe("系统管理", () => { }) }) + it("「其他」页签展示生效表前缀,切换「开放初始化页面」开关提交 setupPageEnabled", async () => { + vi.mocked(adminApi.settings).mockResolvedValue( + adminSettings({ + setupPageEnabled: false, + tablePrefix: "custom_prefix_" + }) + ) + vi.mocked(adminApi.updateSettings).mockResolvedValue( + adminSettings({ + setupPageEnabled: true, + tablePrefix: "custom_prefix_" + }) + ) + + const user = userEvent.setup() + renderAdmin("/admin/others") + + expect( + await screen.findByRole("heading", { name: "其他" }) + ).toBeInTheDocument() + expect(screen.getByText("custom_prefix_")).toBeInTheDocument() + + const setupSwitch = screen.getByRole("switch") + expect(setupSwitch).toHaveAttribute("aria-checked", "false") + + await user.click(setupSwitch) + expect(adminApi.updateSettings).toHaveBeenCalledWith({ + setupPageEnabled: true + }) + }) + it("新建用户:提交邮箱与角色,成功后就地展示一次性密码,关闭即消失", async () => { vi.mocked(adminApi.settings).mockResolvedValue(adminSettings()) const created = adminCreatedUser() @@ -763,23 +790,43 @@ describe("全局文件限额", () => { ).toBeInTheDocument() unmountLimits() - const { unmount: unmount3 } = renderAdmin("/admin/database") + // 3. 直达 /admin/others + const { unmount: unmount3 } = renderAdmin("/admin/others") expect( - await screen.findByRole("heading", { name: "数据库维护" }) + await screen.findByRole("heading", { name: "其他" }) ).toBeInTheDocument() unmount3() + // 4. 旧路径 /admin/database 与 /admin/maintenance 直接替换不留重定向,回落至首 tab /admin/email + const { unmount: unmountDb } = renderAdmin("/admin/database") + expect( + await screen.findByRole("heading", { name: "邮件配置" }) + ).toBeInTheDocument() + unmountDb() + const { unmount: unmountLegacy } = renderAdmin("/admin/maintenance") expect( - await screen.findByRole("heading", { name: "数据库维护" }) + await screen.findByRole("heading", { name: "邮件配置" }) ).toBeInTheDocument() unmountLegacy() + const { unmount: unmountQueryOthers } = renderAdmin("/admin?tab=others") + expect( + await screen.findByRole("heading", { name: "其他" }) + ).toBeInTheDocument() + unmountQueryOthers() + + const { unmount: unmountQueryDb } = renderAdmin("/admin?tab=database") + expect( + await screen.findByRole("heading", { name: "邮件配置" }) + ).toBeInTheDocument() + unmountQueryDb() + const { unmount: unmountQueryMaint } = renderAdmin( "/admin?tab=maintenance" ) expect( - await screen.findByRole("heading", { name: "数据库维护" }) + await screen.findByRole("heading", { name: "邮件配置" }) ).toBeInTheDocument() unmountQueryMaint() diff --git a/web/src/pages/admin/admin-page.tsx b/web/src/pages/admin/admin-page.tsx index 3192aa2..5276721 100644 --- a/web/src/pages/admin/admin-page.tsx +++ b/web/src/pages/admin/admin-page.tsx @@ -33,11 +33,7 @@ export function AdminUsersTab() { export function AdminIndexRedirect() { const [searchParams] = useSearchParams() const tab = searchParams.get("tab") - const target = !tab - ? "/admin/email" - : tab === "maintenance" - ? "/admin/database" - : `/admin/${tab}` + const target = !tab ? "/admin/email" : `/admin/${tab}` return } @@ -61,8 +57,7 @@ export function AdminPage() { }, [load]) const segments = location.pathname.split("/").filter(Boolean) - const currentTab = - segments[1] === "database" ? "maintenance" : segments[1] || "email" + const currentTab = segments[1] || "email" return (
@@ -93,10 +88,8 @@ export function AdminPage() { {t("admin.tabs.limits")} - - - {t("admin.tabs.maintenance")} - + + {t("admin.tabs.others")} diff --git a/web/src/pages/admin/maintenance-section.tsx b/web/src/pages/admin/others-section.tsx similarity index 86% rename from web/src/pages/admin/maintenance-section.tsx rename to web/src/pages/admin/others-section.tsx index 664ceb6..4ee02fb 100644 --- a/web/src/pages/admin/maintenance-section.tsx +++ b/web/src/pages/admin/others-section.tsx @@ -7,11 +7,11 @@ import { describeApiError } from "@/lib/api-errors" import type { AdminSettings } from "@/lib/api-types" /** - * 系统管理 · 数据库维护(规格 §5.3.5、§6.1)。 + * 系统管理 · 其他(规格 §5.3.5、§6.1)。 * * 「开放初始化页面」只门控页面,不门控密钥接口。 */ -export function MaintenanceSection(props?: { +export function OthersSection(props?: { settings?: AdminSettings onSaved?: (settings: AdminSettings) => void }) { @@ -42,14 +42,14 @@ export function MaintenanceSection(props?: { return (

- {t("admin.maintenance.title")} + {t("admin.others.title")}