hjjjj e4c1ff7900
Some checks failed
Deploy skills-market-server / deploy (push) Has been cancelled
feat(admin): 添加管理员面板和权限管理功能
新增管理员面板的静态文件支持,提供用户列表、角色切换和权限配置功能。更新了环境变量示例以包含管理员邮箱,并在auth.js中实现了管理员登录和权限审计日志功能。更新README文档以说明管理员面板的使用和相关接口。
2026-03-24 16:57:33 +08:00

111 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Skills Market Server
Skills Market API 服务,使用 Express + MongoDB。
## 安装 MongoDB
### Windows
1. 下载 MongoDB Community Edition: https://www.mongodb.com/try/download/community
2. 安装后MongoDB 会作为 Windows 服务自动启动
3. 默认端口: 27017
### 或使用 Docker
```bash
docker run -d -p 27017:27017 --name mongodb mongo:latest
```
## 启动服务
```bash
# 安装依赖
npm install
# 启动服务
npm start
# 开发模式(自动重启)
npm run dev
```
## API 接口
| 接口 | 方法 | 说明 |
|------|------|------|
| `/api/skills` | GET | 获取 skills 列表 |
| `/api/skills/:name` | GET | 获取 skill 详情 |
| `/api/skills/:name/download` | GET | 下载 skill增加下载计数 |
| `/api/skills/:name/publish` | POST | 发布/更新 skill |
| `/api/skills/:name/versions` | GET | 获取版本历史 |
| `/api/skills/:name/versions/:version` | GET | 获取特定版本 |
| `/api/skills/:name` | DELETE | 删除 skill |
| `/api/health` | GET | 健康检查 |
| `/api/stats` | GET | 统计信息 |
### 云端会话 `/api/chat/*`(需 Bearer JWT与发布 skill 同源鉴权)
| 接口 | 方法 | 说明 |
|------|------|------|
| `/api/chat/sessions` | GET | 列出当前用户的会话 |
| `/api/chat/sessions` | POST | 创建会话body 含客户端生成的 `id` |
| `/api/chat/sessions/:id` | PATCH | 更新会话字段 |
| `/api/chat/sessions/:id` | DELETE | 删除会话及其消息 |
| `/api/chat/sessions/:id/messages` | GET | 分页消息,`view=user`(裁剪 tool/thinking 等)或 `view=full` |
| `/api/chat/sessions/:id/messages` | POST | 追加消息 |
| `/api/chat/messages/:messageId` | PATCH | 更新单条消息 |
| `/api/chat/sessions/:id/messages/all` | DELETE | 清空该会话全部消息 |
| `/api/chat/sessions/:id/messages/from/:fromSort` | DELETE | 删除 `sort_order >= fromSort` 的消息(截断) |
### 管理员看板 `/admin`
- 地址:`http://<server>:3001/admin`
- 登录方式:管理员邮箱验证码登录(`/api/auth/send-code` + `/api/admin/login`
- 管理能力:用户列表、角色切换、权限配置(模式可见性 / 技能页 / 智能体页 / SSH 页 / 开发者模式)
- 相关接口:`/api/admin/login``/api/admin/users``/api/admin/users/:userId/permissions``/api/admin/audit-logs`
- 权限规则:`ADMIN_EMAIL` 为初始管理员root admin其他管理员只能编辑非 admin 用户,且不能修改自己的权限
## 环境变量
创建 `.env` 文件:
```
PORT=3001
MONGO_URL=mongodb://localhost:27017
DB_NAME=skills_market
```
## MongoDB 数据结构
```javascript
// skills 集合
{
"_id": ObjectId("..."),
"name": "agent-browser",
"description": "Browser automation...",
"owner": "user123",
"downloads": 150,
"is_public": true,
"tags": ["browser", "automation"],
// 文件数组
"files": [
{ "path": "SKILL.md", "content": "---\nname: ..." },
{ "path": "references/commands.md", "content": "# Commands..." },
{ "path": "templates/auth.sh", "content": "#!/bin/bash..." }
],
// 版本历史
"versions": [
{
"version": 1,
"description": "Initial version",
"files": [ /* 快照 */ ],
"created_at": ISODate("..."),
"created_by": "user123"
}
],
"created_at": ISODate("..."),
"updated_at": ISODate("...")
}
```