docs: document admin groups, OAuth redirect, and API renames

This commit is contained in:
RhenCloud 2026-08-03 00:33:18 +08:00
parent 8c8cfbf211
commit 8c9720b1b3
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
10 changed files with 324 additions and 142 deletions

View file

@ -16,31 +16,40 @@ npm run dev # 启动本地开发服务器
src/
├── index.ts # CF Workers 入口 (fetch + scheduled),导出 DiscordGateway DO
├── types.ts # Env、Config、Route、Filter、WebhookEvent、FormattedMessage
├── config.ts # 从 KV 加载路由(回退到 7 条默认),从 env 构建 Config
├── server.ts # Hono 应用: /health、/webhook挂载 /auth + /
├── config.ts # 从 KV 加载路由(未设置时返回 []),从 env 构建 Config
├── server.ts # Hono 应用: /health、/webhook挂载 /auth、/admin + /
├── webhook.ts # HMAC 验证 (Web Crypto)、parseEvent、extractBranch、matchRoute
├── discord.ts # 通过 DO RPC 分发、initGateway (scheduled)
├── discord.ts # 通过 Discord REST 分发(启用 Gateway 时走 DO RPC、initGateway (scheduled)
├── discord-rest.ts # Discord REST sendMessage带重试和限流处理
├── discord-gateway.ts # Durable Object: Discord Gateway WS、心跳、频道缓存、发送
├── formatter.ts # 23 种事件格式化器 + 通用回退
├── github-oauth.ts # OAuth URL、回调 Token 交换、getUserOctokit
├── oauth-routes.ts # GET /auth/github、回调、DELETE /token/:userId (KV 状态)
├── action-routes.ts # POST /api/comment|merge|react (通过 KV 查找进行 Bearer Token 鉴权)
├── action-routes.ts # POST /api/comment|merge|close|react (通过 KV 查找进行 Bearer Token 鉴权)
├── admin-routes.ts # /admin API路由、分组、me、日志会话 + 权限范围鉴权)
├── admin-session.ts # 管理员会话 CRUD (KV session:{id})、Cookie 辅助函数
├── groups.ts # 分组加载、分组管理员权限范围
├── i18n.ts # 消息语言覆盖 (en/zh)
├── send-log.ts # 发送日志 (logs:send KV 键)
├── token-store.ts # 基于 KV 的 Token CRUD带 findUserIdByToken 反向查找
├── home-routes.ts # 落地页路由
├── legal-routes.ts # 法律页面路由
└── log.ts # JSON 控制台日志 (info/warn/error/fatal)
```
## 脚本
| 命令 | 说明 |
| --- | --- |
| `npm run dev` | 启动 wrangler dev 服务器 |
| `npm run typecheck` | TypeScript 类型检查 |
| `npm run lint` | ESLint (TypeScript) |
| `npm run lint:md` | Markdownlint (Markdown) |
| `npm run format` | 使用 Prettier 格式化所有文件 |
| `npm run format:check` | 检查 Prettier 格式 |
| `npm run docs:dev` | 启动 VitePress 文档开发服务器 |
| `npm run docs:build` | 构建文档站点 |
| 命令 | 说明 |
| ---------------------- | ----------------------------- |
| `npm run dev` | 启动 wrangler dev 服务器 |
| `npm run typecheck` | TypeScript 类型检查 |
| `npm run lint` | ESLint (TypeScript) |
| `npm run lint:md` | Markdownlint (Markdown) |
| `npm test` | 运行单元测试 (bun test) |
| `npm run format` | 使用 Prettier 格式化所有文件 |
| `npm run format:check` | 检查 Prettier 格式 |
| `npm run docs:dev` | 启动 VitePress 文档开发服务器 |
| `npm run docs:build` | 构建文档站点 |
## 代码风格
@ -56,10 +65,10 @@ src/
## 测试
```bash
# 功能测试(需要正在运行的 wrangler dev
bash /tmp/test-webhooker.sh
# 运行单元测试套件 (bun test)
npm test
# 或手动
# 或手动检查健康端点
curl http://localhost:8787/health
```