编辑文章接口

接口说明

更新已有文章的信息。支持修改文章的所有属性,包括分类、标题、内容、发布日期等信息,可以更改文章的私密性和访问密码。

  • 接口URL: /api/articles/update
  • 请求方法: POST
  • 权限要求: 必须登录后使用,需要有效的JWT令牌

请求参数

参数名 类型 必填 说明 示例值
article_id number 要编辑的文章ID 1
article_classify_id number 文章分类ID 1
article_title string 文章标题 "更新后的文章标题"
article_title_image string 文章标题图片URL "https://example.com/new-image.jpg"
article_text string 文章内容 "更新后的文章内容..."
article_date string 文章发布日期 "2024-01-01"
article_copyright string 文章版权信息 "版权所有©2024"
article_keywords string 文章关键词 "技术,博客,更新"
article_private number 是否私密文章(0:否, 1:是) 0
article_password string 文章访问密码 "newpassword"

响应结构

typescript 复制代码
interface Response {
  code: number;      // 状态码
  message: string;   // 响应消息
  data: null;        // 无返回数据
}

响应示例

json 复制代码
{
  "code": 0,
  "message": "文章修改成功",
  "data": null
}

特殊说明

权限验证

  • 必须携带有效的JWT令牌才能调用此接口
  • 未登录或令牌失效将返回401错误

更新规则

  • 所有必填字段都必须提供,即使不需要修改
  • 选填字段如果不需要修改,可以传入原值或空值
  • 文章ID必须存在,否则更新将失败

文章属性变更

  • 可以通过修改article_private切换文章的私密状态
  • 可以通过设置或清空article_password修改文章的访问限制
  • 修改分类ID时请确保目标分类存在

错误码说明

错误码 说明 处理建议
0 成功 -
401 未登录或登录失效 请先登录或更新令牌
404 文章不存在 检查文章ID是否正确
500 服务器错误 请联系管理员

调用示例

基础更新

typescript 复制代码
const response = await fetch('/api/articles/update', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your-jwt-token'
  },
  body: JSON.stringify({
    article_id: 1,
    article_classify_id: 1,
    article_title: "更新后的文章标题",
    article_text: "更新后的文章内容...",
    article_date: "2024-01-01"
  })
});

修改文章属性

typescript 复制代码
const response = await fetch('/api/articles/update', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your-jwt-token'
  },
  body: JSON.stringify({
    article_id: 1,
    article_classify_id: 2,
    article_title: "更新后的文章标题",
    article_text: "更新后的文章内容...",
    article_date: "2024-01-01",
    article_private: 1,
    article_password: "newpassword"
  })
});