Mangogo 营业厅Mangogo 营业厅
首页API 参考Skills插件

2.2 根据灵感分类查询作品列表

POST/api/inspiration/works

2.2 根据灵感分类查询作品列表

根据灵感分类查询作品列表

接口描述: 根据灵感分类查询作品列表,支持可选登录验证,支持分页查询

请求方式: POST

请求路径: /api/inspiration/works

请求头:

参数名类型必填说明
tokenstring否用户登录令牌,如果提供则返回当前用户的收藏和点赞状态

请求参数:

{  "category_parent_id": 0,  "category_id": 0,  "page": 1,  "page_size": 20,  "sort_type": 0}
参数名类型必填说明
category_parent_idint是父分类ID(>=0),0表示查询所有作品
category_idint是分类ID(>=0),当 category_parent_id > 0 时使用
pageint否页码,默认为1
page_sizeint否每页数量,默认为20,最大100
sort_typeint否排序类型,默认为0。0=推荐值降序,1=热度值降序,2=发布时间降序。其他值将返回错误

查询逻辑:

  1. 当 category_parent_id = 0 时:查询所有 publish_status = 1、is_public = 1、deleted = 0 的作品
  2. 当 category_parent_id > 0 且 category_id = 0 时:
    • 查询所有 parent_id = category_parent_id 且 status = 1 的子分类ID
    • 查询 creation_classification 表中 category_ids 包含这些子分类ID的作品
    • 返回符合条件的作品列表
  3. 当 category_parent_id > 0 且 category_id > 0 时:
    • 查询 creation_classification 表中 category_ids 包含 category_id 的作品
    • 返回符合条件的作品列表
  4. 排序规则:
    • 当 sort_type = 0 时:按 recommended_value(推荐值)降序排序
    • 当 sort_type = 1 时:按 heat_value(热度值)降序排序
    • 当 sort_type = 2 时:按 published_at(发布时间)降序排序
    • 当 sort_type 为其他值时:返回错误"排序类型错误"

请求示例:

cURL 示例:

# 查询所有作品curl -X POST "https://your-domain.com/api/inspiration/works" \  -H "Content-Type: application/json" \  -d '{    "category_parent_id": 0,    "category_id": 0,    "page": 1,    "page_size": 20,    "sort_type": 0  }'# 查询指定父分类下的所有子分类作品(按热度值降序)curl -X POST "https://your-domain.com/api/inspiration/works" \  -H "Content-Type: application/json" \  -d '{    "category_parent_id": 1,    "category_id": 0,    "page": 1,    "page_size": 20,    "sort_type": 1  }'# 查询指定分类的作品(按发布时间降序)curl -X POST "https://your-domain.com/api/inspiration/works" \  -H "Content-Type: application/json" \  -d '{    "category_parent_id": 1,    "category_id": 22,    "page": 1,    "page_size": 20,    "sort_type": 2  }'

JavaScript/axios 示例:

// 查询所有作品(按推荐值降序)axios.post('https://your-domain.com/api/inspiration/works', {  category_parent_id: 0,  category_id: 0,  page: 1,  page_size: 20,  sort_type: 0}).then(response => {  console.log(response.data);}).catch(error => {  console.error(error);});// 查询指定父分类下的所有子分类作品(按热度值降序)axios.post('https://your-domain.com/api/inspiration/works', {  category_parent_id: 1,  category_id: 0,  page: 1,  page_size: 20,  sort_type: 1}).then(response => {  console.log(response.data);}).catch(error => {  console.error(error);});// 查询指定分类的作品(按发布时间降序)axios.post('https://your-domain.com/api/inspiration/works', {  category_parent_id: 1,  category_id: 22,  page: 1,  page_size: 20,  sort_type: 2}).then(response => {  console.log(response.data);}).catch(error => {  console.error(error);});

fetch 示例:

// 查询所有作品(按推荐值降序)fetch('https://your-domain.com/api/inspiration/works', {  method: 'POST',  headers: {    'Content-Type': 'application/json'  },  body: JSON.stringify({    category_parent_id: 0,    category_id: 0,    page: 1,    page_size: 20,    sort_type: 0  })}).then(response => response.json()).then(data => {  console.log(data);}).catch(error => {  console.error(error);});

Python requests 示例:

# 查询所有作品(按推荐值降序)response = requests.post(    'https://your-domain.com/api/inspiration/works',    json={        'category_parent_id': 0,        'category_id': 0,        'page': 1,        'page_size': 20,        'sort_type': 0    })print(response.json())# 查询指定父分类下的所有子分类作品(按热度值降序)response = requests.post(    'https://your-domain.com/api/inspiration/works',    json={        'category_parent_id': 1,        'category_id': 0,        'page': 1,        'page_size': 20,        'sort_type': 1    })print(response.json())# 查询指定分类的作品(按发布时间降序)response = requests.post(    'https://your-domain.com/api/inspiration/works',    json={        'category_parent_id': 1,        'category_id': 22,        'page': 1,        'page_size': 20,        'sort_type': 2    })print(response.json())

成功响应 (200):

{  "code": 0,  "success": true,  "message": "",  "data": {    "total": 100,    "items": [      {        "id": 1,        "user_id": 1,        "username": "user123",        "display_name": "张三",        "avatar_url": "https://example.com/avatar.jpg",        "work_type": 2,        "save_method": 1,        "cover_url": "https://example.com/cover.jpg",        "resource_url": "https://example.com/resource.jpg",        "work_at": 1718000000,        "name": "作品名称",        "creation_prompt": "创作提示词",        "classtag": "分类标签",        "category_id": 22,        "view_count": 100,        "like_count": 50,        "collect_count": 20,        "heat_value": 1000,        "created_at": 1718000000,        "resolved_json": "{\"prompt\":\"...\",\"params\":{...}}",        "is_deleted": 0,        "is_like": 0,        "is_focus": 0,        "purchased": true,        "fee": 500000,        "fee_usd": 1.0      }    ]  }}

错误响应 (200):

{  "code": 400,  "success": false,  "message": "参数错误: category_parent_id must be >= 0",  "data": null}

字段说明:

字段名类型说明
codeint状态码(0=成功)
successbool是否成功
messagestring消息
dataobject返回数据
data.totalint总条数
data.itemsarray作品列表数组
data.items[].idint作品ID
data.items[].user_idint用户ID
data.items[].usernamestring用户名
data.items[].display_namestring显示名称
data.items[].avatar_urlstring用户头像URL
data.items[].work_typeint作品类型(1=文本 2=图片 3=视频 4=音频)
data.items[].save_methodint保存方式(1=AI创作 2=手动上传)
data.items[].cover_urlstring封面URL
data.items[].resource_urlstring资源URL
data.items[].source_typeint来源类型(0无 1常规 2应用)
data.items[].source_idint来源ID
data.items[].work_atint64作品时间戳
data.items[].namestring作品名称
data.items[].creation_promptstring创作提示词
data.items[].classtagstring分类标签
data.items[].category_idint分类ID
data.items[].view_countint浏览次数
data.items[].like_countint点赞次数
data.items[].collect_countint收藏次数
data.items[].heat_valueint热度值
data.items[].created_atint64创建时间戳
data.items[].resolved_jsonstring解析后的JSON数据(work_type=2时来自image_generations,work_type=3时来自video_generations,work_type=4时来自audio_generations)
data.items[].is_deletedint当前用户的收藏状态(0=已收藏,1=未收藏),未登录时默认为1
data.items[].is_likeint当前用户的点赞状态(0=已点赞,1=未点赞),未登录时默认为1
data.items[].is_focusint当前用户对作品作者的关注状态(0=已关注,1=未关注/取消关注),未登录时默认为1
data.items[].purchasedbool当前用户是否已购买该作品(true=已购买,false=未购买),未登录时默认为false
data.items[].feeint作品费用(配额单位)
data.items[].fee_usdfloat64作品费用(USD单位),换算公式:fee_usd = fee / 500000

注意事项:

  • 支持可选登录验证,用户可以不传 token 访问
  • 如果用户提供了 token,系统会验证用户登录信息并返回当前用户的收藏、点赞、关注和购买状态
  • 如果用户未登录或未提供 token,返回数据中 is_deleted、is_like 和 is_focus 都为 1(未收藏、未点赞、未关注),purchased 为 false(未购买)
  • 只返回已发布(publish_status=1)、公开(is_public=1)、未删除(deleted=0)的作品
  • 返回数据中包含 code 参数,0 表示成功
  • 支持分页查询,默认每页20条,最大100条
  • 作品按 heat_value DESC 排序(热度值降序)
  • 接口支持三种数据库:SQLite、MySQL、PostgreSQL
  • JSON字段查询会根据数据库类型自动选择合适的查询方式