Base URL /api
🔐

认证 Auth

POST /api/auth/login 用户登录 公开

请求体 (JSON)

参数名类型必填说明
usernamestring必填用户名
passwordstring必填密码

请求示例

{
  "username": "admin",
  "password": "your_password"
}

成功响应 200

{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "username": "admin"
}

失败响应 401

{
  "message": "用户名或密码错误"
}
GET /api/auth/registration-status 检查注册功能是否开放 公开
{
  "enabled": true
}
POST /api/auth/send-code 发送邮箱验证码 公开
参数名类型必填说明
emailstring必填接收验证码的邮箱地址
{
  "email": "user@example.com"
}

成功响应 200

{
  "message": "验证码已发送",
  "expiresIn": 300
}
POST /api/auth/verify-register 验证邮箱并注册 公开
参数名类型必填说明
emailstring必填邮箱地址
codestring必填邮箱收到的验证码
usernamestring必填用户名
passwordstring必填密码(至少 6 位)
{
  "email": "user@example.com",
  "code": "123456",
  "username": "new_user",
  "password": "123456"
}

成功响应 201

{
  "message": "注册成功,请登录"
}
GET /api/auth/me 获取当前用户信息 需认证

请求头

参数名类型必填说明
Authorizationstring必填Bearer <token>,登录后获取

成功响应 200

{
  "_id": "665a1b2c...",
  "username": "admin",
  "email": "admin@example.com",
  "emailVerified": true,
  "createdAt": "2024-06-01T00:00:00.000Z"
}
POST /api/auth/register 管理员注册(首个用户无需认证,后续需认证) 条件
参数名类型必填说明
usernamestring必填用户名
passwordstring必填密码
{
  "message": "注册成功"
}
📝

文章 Articles

GET /api/articles 获取文章列表(分页、筛选) 公开
参数名类型必填说明
pagenumber可选页码,默认 1
limitnumber可选每页数量,默认 10
categorystring可选按分类筛选
tagstring可选按标签筛选
publishedboolean可选是否已发布(true/false)
{
  "articles": [{
    "_id": "665a1b2c...",
    "title": "Hello World",
    "slug": "hello-world",
    "content": "# Hello World\n...",
    "excerpt": "文章摘要",
    "categories": ["技术"],
    "tags": ["Hexo", "Blog"],
    "thumbnail": "",
    "published": true,
    "toc": true,
    "createdAt": "2024-06-01T00:00:00.000Z",
    "updatedAt": "2024-06-01T00:00:00.000Z"
  }],
  "totalPages": 5,
  "currentPage": 1,
  "total": 42
}
GET /api/articles/id/:id 按 ID 获取文章 公开
参数名位置类型必填说明
idpathstring必填文章 MongoDB ID
{
  "_id": "665a1b2c...",
  "title": "Hello World",
  "slug": "hello-world",
  "content": "# Hello World\n## 这是第一篇文章",
  "categories": ["技术"],
  "tags": ["Hexo"],
  "published": true,
  "createdAt": "2024-06-01T00:00:00.000Z",
  "updatedAt": "2024-06-01T00:00:00.000Z"
}
GET /api/articles/:slug 按 slug 获取文章 公开
参数名位置类型说明
slugpathstring文章 URL 友好标识
// GET /api/articles/hello-world
{
  "_id": "665a1b2c...",
  "title": "Hello World",
  "slug": "hello-world",
  "content": "# Hello World\n...",
  "published": true
}
POST /api/articles 创建文章 需认证
参数名类型必填说明
titlestring必填文章标题
contentstring必填Markdown 正文内容
categoriesstring[]可选分类列表
tagsstring[]可选标签列表
publishedboolean可选是否直接发布,默认 false
thumbnailstring可选封面图 URL
tocboolean可选是否显示目录,默认 true

请求示例

{
  "title": "我的新文章",
  "content": "## 正文内容\n这是文章正文。\n\n",
  "categories": ["技术", "前端"],
  "tags": ["React", "TypeScript"],
  "published": false
}

成功响应 201

{
  "_id": "665a1b2c...",
  "title": "我的新文章",
  "slug": "wo-de-xin-wen-zhang",
  "content": "## 正文内容\n...",
  "categories": ["技术", "前端"],
  "tags": ["React", "TypeScript"],
  "published": false,
  "createdAt": "2024-06-01T00:00:00.000Z",
  "updatedAt": "2024-06-01T00:00:00.000Z"
}
PUT /api/articles/:id 更新文章 需认证
参数名类型必填说明
titlestring可选新标题(更新后 slug 自动重新生成)
contentstring可选Markdown 正文
categoriesstring[]可选分类列表
tagsstring[]可选标签列表
publishedboolean可选发布状态
// 返回更新后的完整文章对象
{
  "_id": "665a1b2c...",
  "title": "更新后的标题",
  "slug": "geng-xin-hou-de-biao-ti",
  "content": "更新后的内容...",
  "published": true,
  "updatedAt": "2024-06-02T00:00:00.000Z"
}
DELETE /api/articles/:id 删除文章 需认证
{
  "message": "文章已删除"
}
POST /api/articles/:id/publish 发布文章(触发 Hexo 生成) 需认证
{
  "message": "文章已发布",
  "article": { ... }
}
PUT /api/articles/:id/date 修改发布时间(仅 admin) 需认证+Admin
参数名类型必填说明
createdAtstring必填ISO 8601 日期字符串
{
  "message": "文章时间已更新",
  "article": { ... }
}
⚙️

配置 Config

GET /api/config 获取所有配置 公开
[
  {
    "_id": "...",
    "key": "beian",
    "value": "蜀ICP备xxxx号",
    "updatedAt": "2024-06-01T00:00:00.000Z"
  },
  {
    "_id": "...",
    "key": "registration_enabled",
    "value": "true"
  }
]
GET /api/config/:key 按 key 获取单个配置 公开
参数名位置类型说明
keypathstring配置键名,例如 beian、registration_enabled
// GET /api/config/beian
{
  "_id": "...",
  "key": "beian",
  "value": "蜀ICP备xxxx号",
  "updatedAt": "2024-06-01T00:00:00.000Z"
}
PUT /api/config/:key 更新配置 需认证
参数名类型必填说明
valuestring必填新的配置值
{
  "_id": "...",
  "key": "beian",
  "value": "蜀ICP备xxxx号-1",
  "updatedAt": "2024-06-02T00:00:00.000Z"
}
POST /api/config/batch 批量更新配置 需认证
参数名类型必填说明
configsobject[]必填配置数组 [{key, value}]
// 请求
{
  "configs": [
    { "key": "beian", "value": "蜀ICP备xxxx号-1" },
    { "key": "site_title", "value": "My Blog" }
  ]
}

// 响应
[
  { "_id": "...", "key": "beian", "value": "蜀ICP备xxxx号-1", ... },
  { "_id": "...", "key": "site_title", "value": "My Blog", ... }
]
👥

用户 Users

GET /api/users 用户列表(不含密码) 需认证
[
  {
    "_id": "665a1b2c...",
    "username": "admin",
    "email": "admin@example.com",
    "emailVerified": true,
    "createdAt": "2024-06-01T00:00:00.000Z"
  }
]
POST /api/users 创建用户 需认证
参数名类型必填说明
usernamestring必填用户名(唯一)
passwordstring必填密码(至少 6 位)
{
  "_id": "665a1b2c...",
  "username": "new_user",
  "createdAt": "2024-06-01T00:00:00.000Z"
}
DELETE /api/users/:id 删除用户(不能删除自己) 需认证
{
  "message": "用户已删除"
}
PUT /api/users/:id/reset-password 重置用户密码 需认证
参数名类型必填说明
passwordstring必填新密码(至少 6 位)
{
  "message": "密码已重置"
}

TODO 事项

GET /api/todos 获取 TODO 列表(支持筛选) 公开
参数名类型必填说明
completedboolean可选筛选完成状态(true/false)
prioritystring可选按优先级筛选:low / medium / high
tagstring可选按标签筛选
[
  {
    "_id": "665a1b2c...",
    "title": "完成 API 文档",
    "content": "编写完整的接口文档",
    "completed": false,
    "priority": "high",
    "dueDate": "2024-06-30T00:00:00.000Z",
    "tags": ["文档", "API"],
    "notes": "需要包含所有接口",
    "createdAt": "2024-06-01T00:00:00.000Z",
    "updatedAt": "2024-06-01T00:00:00.000Z"
  }
]
POST /api/todos 创建 TODO 公开
参数名类型必填说明
titlestring必填标题(最多 200 字符)
contentstring可选内容(最多 2000 字符)
prioritystring可选优先级:low / medium(默认)/ high
dueDatestring可选截止日期 ISO 字符串
tagsstring[]可选标签列表(每个最多 50 字符)
notesstring可选备注(最多 1000 字符)
// 请求
{
  "title": "写周报",
  "priority": "high",
  "tags": ["工作", "周报"],
  "dueDate": "2024-06-07T00:00:00.000Z"
}

// 响应 201
{
  "_id": "665a1b2c...",
  "title": "写周报",
  "priority": "high",
  "tags": ["工作", "周报"],
  "completed": false,
  "createdAt": "2024-06-01T00:00:00.000Z"
}
PUT /api/todos/:id 更新 TODO 公开
// 返回更新后的完整 TODO 对象
{
  "_id": "665a1b2c...",
  "title": "写周报(已更新)",
  "completed": true,
  "updatedAt": "2024-06-02T00:00:00.000Z"
}
DELETE /api/todos/:id 删除 TODO 公开
{
  "message": "删除成功"
}
PATCH /api/todos/:id/toggle 切换完成状态 公开
{
  "_id": "665a1b2c...",
  "title": "写周报",
  "completed": true,
  ...
}
🌐

翻译 Translate

POST /api/translate 翻译文本(多引擎) 公开
参数名类型必填说明
querystring必填待翻译文本
fromstring可选源语言,默认 auto
tostring可选目标语言,默认 en
// 请求
{
  "query": "你好世界",
  "from": "zh",
  "to": "en"
}

// 响应(同时返回百度+腾讯+Azure翻译结果)
{
  "results": [
    {
      "source": "baidu",
      "result": "Hello world"
    },
    {
      "source": "tencent",
      "result": "Hello World"
    },
    {
      "source": "azure",
      "result": "Hello, world"
    }
  ]
}
POST /api/translate/folder-name 中文名转英文文件夹名 公开
参数名类型必填说明
namestring必填中文名称
// 请求
{ "name": "我的第一个项目" }

// 响应
{
  "results": [
    { "source": "baidu", "result": "my-first-project" },
    { "source": "tencent", "result": "my-first-project" }
  ]
}
🖼️

Unsplash 图片

GET /api/unsplash/photo-url 获取 Unsplash 图片直链 公开
参数名位置类型必填说明
urlquerystring必填Unsplash 图片页面 URL
// GET /api/unsplash/photo-url?url=https://unsplash.com/photos/abc123

{
  "photoUrl": "https://images.unsplash.com/photo-xxx?w=1920",
  "author": "Photographer Name",
  "authorUrl": "https://unsplash.com/@author"
}