- Console:React 19 + antd 6.6.5 前端(登录 admin/admin)+ Hono 管理 API (Nodes/Domains/Mailboxes/Emails/Webhooks/Keys/OAuth/Admin) - Node:Bun 转发节点(HMAC 签名、有限重试、心跳、结构化日志、优雅退出) - Email Worker:Cloudflare email handler + 本地联调入口 - shared:HMAC 协议(docs/04)、wmh_ Key(32 位)、AES-GCM 加密、SSRF 防护 - 邮件管线:postal-mime 解析、附件、catch-all、限额、malformed 降级、TTL 1 天 - Webhook:签名投递、指数退避重试、SSRF 校验、投递日志 - API v1 + MCP(JSON-RPC,六工具,凭据 kind 隔离) - Cloudflare OAuth:真实 + 本地 sim 模式,自动安装管线(幂等,无需手工命令) - 测试:bun test 41 例(协议安全/管线/TTL/Webhook/SSRF/MCP/OAuth/鉴权)+ Playwright UI 冒烟 - LOGO/favicon 由 codex CLI 生成
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
/** 应用框架:100vh 布局(侧栏 + 顶栏大标题 + 内容区滚动),会话守卫 */
|
|
import { useEffect, useState } from "react";
|
|
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
|
import { Avatar, Dropdown, Layout, Menu } from "antd";
|
|
import {
|
|
DashboardOutlined,
|
|
MailOutlined,
|
|
CloudServerOutlined,
|
|
GlobalOutlined,
|
|
BellOutlined,
|
|
KeyOutlined,
|
|
UserOutlined,
|
|
LogoutOutlined,
|
|
} from "@ant-design/icons";
|
|
import { health, logout, me } from "./api.ts";
|
|
|
|
const { Sider, Header, Content } = Layout;
|
|
|
|
/** # 成员变量: 侧栏菜单项 **/
|
|
const MENU_ITEMS = [
|
|
{ key: "/", icon: <DashboardOutlined />, label: "概览" },
|
|
{ key: "/nodes", icon: <CloudServerOutlined />, label: "节点 Nodes" },
|
|
{ key: "/domains", icon: <GlobalOutlined />, label: "域名 Domains" },
|
|
{ key: "/mailboxes", icon: <MailOutlined />, label: "邮箱 Mailboxes" },
|
|
{ key: "/emails", icon: <MailOutlined />, label: "邮件 Emails" },
|
|
{ key: "/webhooks", icon: <BellOutlined />, label: "Webhooks" },
|
|
{ key: "/keys", icon: <KeyOutlined />, label: "API / MCP Keys" },
|
|
];
|
|
|
|
/** # 成员变量: 路由 -> 页面标题/副标题 **/
|
|
const PAGE_META: Record<string, { title: string; subtitle: string }> = {
|
|
"/": { title: "概览", subtitle: "节点、邮件与投递总览" },
|
|
"/nodes": { title: "节点管理", subtitle: "通过 Cloudflare OAuth 自动安装的转发节点" },
|
|
"/domains": { title: "域名管理", subtitle: "接入 Email Routing 的收件域名" },
|
|
"/mailboxes": { title: "邮箱管理", subtitle: "收件地址与保留策略" },
|
|
"/emails": { title: "邮件", subtitle: "已接收邮件(默认保留 1 天)" },
|
|
"/webhooks": { title: "Webhooks", subtitle: "邮件事件推送与投递日志" },
|
|
"/keys": { title: "API / MCP Keys", subtitle: "wmh_ 前缀凭据,仅创建时可见" },
|
|
};
|
|
|
|
/** # 函数
|
|
* 应用框架组件:未登录跳 /login;顶栏展示页面标题 + 版本号(package.json 来源)
|
|
*/
|
|
export function App() {
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
const [ready, setReady] = useState(false);
|
|
const [username, setUsername] = useState("");
|
|
const [version, setVersion] = useState("");
|
|
|
|
useEffect(() => {
|
|
void (async () => {
|
|
try {
|
|
const [healthInfo, meInfo] = await Promise.all([health(), me()]);
|
|
setVersion(healthInfo.version);
|
|
setUsername(meInfo.user.username);
|
|
setReady(true);
|
|
} catch {
|
|
navigate("/login", { replace: true });
|
|
}
|
|
})();
|
|
}, [navigate]);
|
|
|
|
if (!ready) return null;
|
|
const meta = PAGE_META[location.pathname] ?? { title: "WmailHub", subtitle: "" };
|
|
|
|
return (
|
|
<Layout className="app-layout">
|
|
<Sider width={228} className="app-sider" theme="light">
|
|
<div className="brand">
|
|
<img src="/logo.svg" alt="WmailHub" />
|
|
<span className="name">WmailHub</span>
|
|
</div>
|
|
<Menu
|
|
mode="inline"
|
|
selectedKeys={[location.pathname]}
|
|
items={MENU_ITEMS}
|
|
onClick={({ key }) => navigate(key)}
|
|
style={{ borderInlineEnd: "none" }}
|
|
/>
|
|
</Sider>
|
|
<Layout>
|
|
<Header className="app-header">
|
|
<div>
|
|
<div className="title">{meta.title}</div>
|
|
<div className="subtitle">{meta.subtitle}</div>
|
|
</div>
|
|
<div style={{ display: "flex", alignItems: "center", gap: 14 }}>
|
|
<span className="muted mono">v{version}</span>
|
|
{/* Dropdown 子元素必须是 DOM 元素(antd v6 坑),所以外包 div */}
|
|
<div>
|
|
<Dropdown
|
|
menu={{
|
|
items: [
|
|
{
|
|
key: "logout",
|
|
icon: <LogoutOutlined />,
|
|
label: "退出登录",
|
|
onClick: async () => {
|
|
await logout().catch(() => undefined);
|
|
window.location.href = "/login";
|
|
},
|
|
},
|
|
],
|
|
}}
|
|
>
|
|
<div style={{ display: "flex", alignItems: "center", gap: 8, cursor: "pointer" }}>
|
|
<Avatar size={30} icon={<UserOutlined />} />
|
|
<span>{username}</span>
|
|
</div>
|
|
</Dropdown>
|
|
</div>
|
|
</div>
|
|
</Header>
|
|
<Content className="app-content">
|
|
<Outlet />
|
|
</Content>
|
|
</Layout>
|
|
</Layout>
|
|
);
|
|
}
|