Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const ForgotPasswordPage = lazy(() =>
default: m.ForgotPasswordPage,
})),
);
const SetupPage = lazy(() =>
import("@/pages/setup/SetupPage").then((m) => ({ default: m.SetupPage })),
);
const ItemNewPage = lazy(() =>
import("@/pages/items/ItemNewPage").then((m) => ({ default: m.ItemNewPage })),
);
Expand Down Expand Up @@ -71,6 +74,11 @@ const AdminSecurityPage = lazy(() =>
default: m.AdminSecurityPage,
})),
);
const AdminSystemPage = lazy(() =>
import("@/pages/admin/AdminSystemPage").then((m) => ({
default: m.AdminSystemPage,
})),
);
const AboutPage = lazy(() =>
import("@/pages/about/AboutPage").then((m) => ({ default: m.AboutPage })),
);
Expand Down Expand Up @@ -137,6 +145,7 @@ export function App() {
</PublicRoute>
}
/>
<Route path="/setup" element={<SetupPage />} />

{/* Protected routes */}
<Route
Expand Down Expand Up @@ -170,6 +179,7 @@ export function App() {
<Route path="app" element={<AdminAppPage />} />
<Route path="email" element={<AdminEmailPage />} />
<Route path="security" element={<AdminSecurityPage />} />
<Route path="system" element={<AdminSystemPage />} />
</Route>
</Route>

Expand Down
30 changes: 30 additions & 0 deletions web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,34 @@ export const api = {
request<T>(path, { method: "DELETE", ...opts }),
};

// Public setup endpoints (no auth): use raw fetch because /api/setup requires the
// X-Setup-Secret header and its errors are status-coded (403 wrong secret, 429 rate
// limited), not the 401/session flow the generic `request` wrapper handles.
export interface SetupResult {
success: boolean;
alreadyInitialized?: boolean;
}

export const setupApi = {
state: async (): Promise<{ enabled: boolean }> => {
const res = await fetch(`${BASE_URL}/setup/state`, {
credentials: "include",
});
if (!res.ok) throw new Error("Setup state unavailable");
return res.json();
},
run: async (secret: string): Promise<SetupResult> => {
const res = await fetch(`${BASE_URL}/setup`, {
method: "POST",
headers: { "X-Setup-Secret": secret },
credentials: "include",
});
const body = await res.json().catch(() => ({}));
if (!res.ok) {
throw new ApiError(res.status, body.error || "Request failed");
}
return body as SetupResult;
},
};

export { ApiError };
30 changes: 29 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,18 @@
"testEmail": "Send Test Email",
"testEmailAddress": "Test recipient address",
"testEmailSent": "Test email sent successfully",
"testEmailFailed": "Failed to send test email"
"testEmailFailed": "Failed to send test email",
"setupPage": "Allow access to the setup page",
"setupPageDesc": "Allow access to the /setup page. Disabling only hides the page; POST /api/setup still works with the secret.",
"dbMaintenance": "Database Maintenance",
"dbMaintenanceDesc": "Check and upgrade the database structure directly, without SETUP_SECRET.",
"checkUpgradeDb": "Check and upgrade database",
"checkingDb": "Checking...",
"dbUpToDate": "The database is already up to date",
"dbInitialized": "Database initialized successfully",
"dbUpgradeFailed": "Upgrade failed, please try again later",
"dbUpgradeUnauthorized": "Please sign in again",
"dbUpgradeForbidden": "Administrator permission required"
},
"channels": {
"title": "Channel Management",
Expand Down Expand Up @@ -364,5 +375,22 @@
"notificationHoursHint": "Notifications are sent at most once per hour. Leave empty to allow every hour.",
"notificationHoursClear": "Clear",
"notificationHoursNoLimit": "No restriction"
},
"setup": {
"title": "Setup",
"desc": "Enter your SETUP_SECRET to initialize or upgrade the database.",
"disabled": "The setup page has been disabled by an administrator.",
"secretLabel": "SETUP_SECRET",
"submit": "Start initialization",
"submitting": "Initializing...",
"alreadyInitialized": "The database is already initialized — no need to run it again.",
"success": "Initialization successful!",
"successGuide": "The database is ready. You can log in or go to the home page.",
"goLogin": "Go to login",
"goHome": "Go to home",
"missingSecret": "Please enter the setup secret.",
"wrongSecret": "Incorrect setup secret.",
"rateLimited": "Too many requests, please try again later.",
"genericError": "Initialization failed, please try again later."
}
}
30 changes: 29 additions & 1 deletion web/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,18 @@
"testEmail": "发送测试邮件",
"testEmailAddress": "测试收件地址",
"testEmailSent": "测试邮件发送成功",
"testEmailFailed": "测试邮件发送失败"
"testEmailFailed": "测试邮件发送失败",
"setupPage": "允许访问初始化页面",
"setupPageDesc": "允许访问 /setup 页面。关闭后页面显示禁用提示;POST /api/setup 仍可用密钥调用。",
"dbMaintenance": "数据库维护",
"dbMaintenanceDesc": "检查并升级数据库结构,无需 SETUP_SECRET。",
"checkUpgradeDb": "检查并升级数据库",
"checkingDb": "检查中...",
"dbUpToDate": "数据库已是最新",
"dbInitialized": "数据库初始化成功",
"dbUpgradeFailed": "升级失败,请稍后再试",
"dbUpgradeUnauthorized": "请重新登录",
"dbUpgradeForbidden": "需要管理员权限"
},
"channels": {
"title": "通道管理",
Expand Down Expand Up @@ -364,5 +375,22 @@
"notificationHoursHint": "每小时仅发送一次通知。不选则每小时都会发送通知。",
"notificationHoursClear": "清空",
"notificationHoursNoLimit": "不限制"
},
"setup": {
"title": "初始化",
"desc": "输入 SETUP_SECRET 密钥以初始化或升级数据库。",
"disabled": "初始化页面已被管理员关闭",
"secretLabel": "SETUP_SECRET 密钥",
"submit": "开始初始化",
"submitting": "初始化中...",
"alreadyInitialized": "数据库已初始化,不需要重复执行。",
"success": "初始化成功!",
"successGuide": "数据库已就绪,请前往登录或首页。",
"goLogin": "前往登录",
"goHome": "前往首页",
"missingSecret": "请输入密钥。",
"wrongSecret": "密钥错误,请检查后重试。",
"rateLimited": "请求过于频繁,请稍后再试。",
"genericError": "初始化失败,请稍后再试。"
}
}
14 changes: 13 additions & 1 deletion web/src/pages/admin/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { NavLink, Outlet, useLocation, useNavigate } from "react-router";
import { Users, Settings, Mail, ShieldCheck, ChevronRight } from "lucide-react";
import {
Users,
Settings,
Mail,
ShieldCheck,
ChevronRight,
Database,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { useIsMobile } from "@/hooks/useIsMobile";

Expand All @@ -22,6 +29,11 @@ export function AdminPage() {
label: t("admin.accessSecurity"),
icon: ShieldCheck,
},
{
to: "/admin/system",
label: t("admin.system"),
icon: Database,
},
];

// Desktop: redirect /admin to /admin/users
Expand Down
Loading
Loading