门户端接口【内部使用】2、灵感广场
2.2 获取灵感详情
POST
/api/inspiration/work/detail2.2 获取灵感详情
获取灵感详情
接口描述: 根据作品ID获取灵感详情,无需登录验证,返回作品详细信息及关联的用户信息。如果用户已登录,会返回当前用户是否已购买该作品的状态。注意:每次调用此接口时,会自动将该作品的浏览次数(view_count)加1
请求方式: POST
请求路径: /api/inspiration/work/detail
请求参数:
{ "id": 1}| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | int | 是 | 作品ID,必须大于0 |
请求示例:
cURL 示例:
curl -X POST "https://your-domain.com/api/inspiration/work/detail" \ -H "Content-Type: application/json" \ -d '{"id": 1}'axios 示例:
axios.post('https://your-domain.com/api/inspiration/work/detail', { id: 1}).then(response => { console.log(response.data);}).catch(error => { console.error(error);});fetch 示例:
fetch('https://your-domain.com/api/inspiration/work/detail', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 1 })}).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/work/detail', json={'id': 1})print(response.json())成功响应 (200):
{ "code": 0, "success": true, "message": "", "data": { "id": 1, "user_id": 100, "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, "username": "user123", "display_name": "用户昵称", "purchased": true, "fee": 500000, "fee_usd": 1.0 }}错误响应 (200):
{ "code": 400, "success": false, "message": "参数错误: id is required", "data": null}{ "code": 404, "success": false, "message": "作品不存在", "data": null}字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码(0=成功) |
| success | bool | 是否成功 |
| message | string | 消息 |
| data | object | 返回数据 |
| data.id | int | 作品ID |
| data.user_id | int | 用户ID |
| data.work_type | int | 作品类型(1=文本 2=图片 3=视频 4=音频) |
| data.save_method | int | 保存方式(1=AI创作 2=手动上传) |
| data.cover_url | string | 封面URL |
| data.resource_url | string | 资源URL |
| data.work_at | int64 | 作品时间戳 |
| data.name | string | 作品名称 |
| data.creation_prompt | string | 创作提示词 |
| data.classtag | string | 分类标签 |
| data.category_id | int | 分类ID |
| data.view_count | int | 浏览次数 |
| data.like_count | int | 点赞次数 |
| data.collect_count | int | 收藏次数 |
| data.heat_value | int | 热度值 |
| data.created_at | int64 | 创建时间戳 |
| data.username | string | 用户名 |
| data.display_name | string | 显示名称 |
| data.purchased | bool | 当前用户是否已购买该作品(true=已购买,false=未购买),未登录时默认为false |
| data.fee | int | 作品费用(配额单位) |
| data.fee_usd | float64 | 作品费用(USD单位),换算公式:fee_usd = fee / QuotaPerUnit(QuotaPerUnit 为系统配置的配额单位换算值,默认为 500000) |
执行逻辑:
- 验证请求参数,确保 id 字段存在且大于0
- 查询 creation_info 表中 id 等于参数 id 且 deleted = 0 的数据
- 如果作品不存在,返回 404 错误
- 根据 creation_info 表的 user_id 关联 users 表的 id,查询用户信息
- 如果用户不存在,返回空的用户名和显示名
- 如果用户已登录(userId > 0),查询 purchase_order 表判断当前用户是否已购买该作品
- 构建响应数据,包含作品信息、用户信息和购买状态
- 返回成功响应,包含 code 参数
注意事项:
- 无需用户登录验证
- 只返回未删除(deleted=0)的作品
- 返回数据中包含
code参数,0 表示成功 - 如果用户不存在,username 和 display_name 字段将为空字符串
- 如果用户已登录,会查询 purchase_order 表判断购买状态;未登录时 purchased 默认为 false
- 接口支持三种数据库:SQLite、MySQL、PostgreSQL