门户端接口【内部使用】2、灵感广场
2.2 根据灵感分类查询作品列表
POST
/api/inspiration/works2.2 根据灵感分类查询作品列表
根据灵感分类查询作品列表
接口描述: 根据灵感分类查询作品列表,支持可选登录验证,支持分页查询
请求方式: POST
请求路径: /api/inspiration/works
请求头:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| token | string | 否 | 用户登录令牌,如果提供则返回当前用户的收藏和点赞状态 |
请求参数:
{ "category_parent_id": 0, "category_id": 0, "page": 1, "page_size": 20, "sort_type": 0}| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| category_parent_id | int | 是 | 父分类ID(>=0),0表示查询所有作品 |
| category_id | int | 是 | 分类ID(>=0),当 category_parent_id > 0 时使用 |
| page | int | 否 | 页码,默认为1 |
| page_size | int | 否 | 每页数量,默认为20,最大100 |
| sort_type | int | 否 | 排序类型,默认为0。0=推荐值降序,1=热度值降序,2=发布时间降序。其他值将返回错误 |
查询逻辑:
- 当
category_parent_id = 0时:查询所有publish_status = 1、is_public = 1、deleted = 0的作品 - 当
category_parent_id > 0且category_id = 0时:- 查询所有
parent_id = category_parent_id且status = 1的子分类ID - 查询
creation_classification表中category_ids包含这些子分类ID的作品 - 返回符合条件的作品列表
- 查询所有
- 当
category_parent_id > 0且category_id > 0时:- 查询
creation_classification表中category_ids包含category_id的作品 - 返回符合条件的作品列表
- 查询
- 排序规则:
- 当
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}字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码(0=成功) |
| success | bool | 是否成功 |
| message | string | 消息 |
| data | object | 返回数据 |
| data.total | int | 总条数 |
| data.items | array | 作品列表数组 |
| data.items[].id | int | 作品ID |
| data.items[].user_id | int | 用户ID |
| data.items[].username | string | 用户名 |
| data.items[].display_name | string | 显示名称 |
| data.items[].avatar_url | string | 用户头像URL |
| data.items[].work_type | int | 作品类型(1=文本 2=图片 3=视频 4=音频) |
| data.items[].save_method | int | 保存方式(1=AI创作 2=手动上传) |
| data.items[].cover_url | string | 封面URL |
| data.items[].resource_url | string | 资源URL |
| data.items[].source_type | int | 来源类型(0无 1常规 2应用) |
| data.items[].source_id | int | 来源ID |
| data.items[].work_at | int64 | 作品时间戳 |
| data.items[].name | string | 作品名称 |
| data.items[].creation_prompt | string | 创作提示词 |
| data.items[].classtag | string | 分类标签 |
| data.items[].category_id | int | 分类ID |
| data.items[].view_count | int | 浏览次数 |
| data.items[].like_count | int | 点赞次数 |
| data.items[].collect_count | int | 收藏次数 |
| data.items[].heat_value | int | 热度值 |
| data.items[].created_at | int64 | 创建时间戳 |
| data.items[].resolved_json | string | 解析后的JSON数据(work_type=2时来自image_generations,work_type=3时来自video_generations,work_type=4时来自audio_generations) |
| data.items[].is_deleted | int | 当前用户的收藏状态(0=已收藏,1=未收藏),未登录时默认为1 |
| data.items[].is_like | int | 当前用户的点赞状态(0=已点赞,1=未点赞),未登录时默认为1 |
| data.items[].is_focus | int | 当前用户对作品作者的关注状态(0=已关注,1=未关注/取消关注),未登录时默认为1 |
| data.items[].purchased | bool | 当前用户是否已购买该作品(true=已购买,false=未购买),未登录时默认为false |
| data.items[].fee | int | 作品费用(配额单位) |
| data.items[].fee_usd | float64 | 作品费用(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字段查询会根据数据库类型自动选择合适的查询方式