feat(note): add audio upload and sharing functionality

- Introduced `note_audio` table for storing audio attachments related to notes.
- Implemented audio upload endpoint in `Note` controller to handle audio file uploads.
- Added sharing functionality with `note_share` table to manage share tokens and view counts.
- Updated API routes to include endpoints for audio uploads and share creation.
- Enhanced documentation to reflect new audio and sharing features.
This commit is contained in:
nepiedg
2026-04-17 10:33:33 +00:00
parent 84e1c0daac
commit 36c506f4bf
15 changed files with 507 additions and 8 deletions
+142 -7
View File
@@ -13,7 +13,9 @@
1. 微信小程序登录
2. 笔记创建、列表、详情、更新、删除
3. 实时转写文本保存
4. AI 总结生成与查询
4. 录音文件上传与播放
5. AI 总结生成与查询
6. 笔记分享与分享只读访问
路由注册位置:
@@ -67,7 +69,7 @@
- [database.sql](/root/work/tp/database.sql#L26)
当前 `note` 模块使用以下 4 张表:
当前 `note` 模块使用以下 6 张表:
1. `note_user`
用于小程序用户登录和用户资料
@@ -81,6 +83,12 @@
4. `note_ai_summary`
AI 总结结果表
5. `note_audio`
录音附件表,保存上传后的音频文件地址与时长
6. `note_share`
分享记录表,保存分享 token 与查看次数
---
## 5. 接口列表
@@ -435,7 +443,48 @@
---
### 5.10 生成 AI 总结
### 5.10 上传录音文件
- 方法:`POST`
- 路径:`/note/v1/item/audio/:id`
- 是否鉴权:是
- Content-Type`multipart/form-data`
表单参数:
| 字段 | 类型 | 必填 | 说明 |
| :--- | :--- | :--- | :--- |
| `audio` | file | 是 | 录音文件 |
| `audio_duration_ms` | int | 否 | 录音时长 |
说明:
- 上传成功后会返回可直接播放的 `audio_url`
- 后端会同步写入 `note_audio`,并更新笔记的录音时长
成功响应示例:
```json
{
"code": 200,
"msg": "上传成功",
"data": {
"audio_id": 2,
"disk": "public",
"file_path": "note/audio/20260417/test.m4a",
"audio_url": "http://127.0.0.1:8000/storage/note/audio/20260417/test.m4a",
"file_size": 20480,
"mime_type": "audio/mp4",
"duration_ms": 18500,
"updated_at": 1710000400
},
"time": 1710000400
}
```
---
### 5.11 生成 AI 总结
- 方法:`POST`
- 路径:`/note/v1/ai/summary/:id`
@@ -492,7 +541,7 @@
---
### 5.11 查看 AI 总结
### 5.12 查看 AI 总结
- 方法:`GET`
- 路径:`/note/v1/ai/summary/:id`
@@ -504,6 +553,90 @@
---
### 5.13 创建分享
- 方法:`POST`
- 路径:`/note/v1/share/create/:id`
- 是否鉴权:是
成功响应示例:
```json
{
"code": 200,
"msg": "分享已生成",
"data": {
"note_id": 10,
"share_token": "7a4d2f2d4a5f1b20f6f9670bb1f4d123",
"share_path": "/pages/note/edit?share_token=7a4d2f2d4a5f1b20f6f9670bb1f4d123",
"title": "会议纪要"
},
"time": 1710000600
}
```
说明:
- 返回 `share_token` 和小程序页面路径
- 小程序可用该路径做转发
---
### 5.14 读取分享内容
- 方法:`GET`
- 路径:`/note/v1/share/read/:token`
- 是否鉴权:否
成功响应示例:
```json
{
"code": 200,
"msg": "success",
"data": {
"id": 10,
"note_user_id": 1,
"title": "会议纪要",
"content": "今天确认了下周需求排期",
"transcript_text": "今天确认了下周需求排期",
"source_type": "mix",
"status": "draft",
"audio_duration_ms": 18500,
"summary_status": "success",
"last_transcript_time": 1710000300,
"created_at": 1710000000,
"updated_at": 1710000600,
"audio": {
"audio_id": 2,
"disk": "public",
"file_path": "note/audio/20260417/test.m4a",
"audio_url": "http://127.0.0.1:8000/storage/note/audio/20260417/test.m4a",
"file_size": 20480,
"mime_type": "audio/mp4",
"duration_ms": 18500,
"updated_at": 1710000400
},
"summary": {
"summary_text": "今天确认了下周需求排期,需要继续跟进接口联调。",
"status": "success"
},
"share": {
"share_token": "7a4d2f2d4a5f1b20f6f9670bb1f4d123",
"title": "会议纪要",
"view_count": 3
}
},
"time": 1710000601
}
```
说明:
- 用于收件人直接查看分享的笔记内容、录音和 AI 摘要
---
## 6. 错误码约定
当前模块沿用项目统一返回结构:
@@ -537,8 +670,10 @@
3. 保存返回的 `token`
4. 创建笔记 `POST /note/v1/item/create`
5. 录音转写过程中持续调用 `POST /note/v1/item/transcript/:id`
6. 需要生成总结时调用 `POST /note/v1/ai/summary/:id`
7. 打开详情页时调用 `GET /note/v1/item/:id`
6. 录音停止后上传录音文件 `POST /note/v1/item/audio/:id`
7. 需要生成总结时调用 `POST /note/v1/ai/summary/:id`
8. 分享前调用 `POST /note/v1/share/create/:id`
9. 打开详情页时调用 `GET /note/v1/item/:id`
---
@@ -546,4 +681,4 @@
1. AI 总结目前是规则版,不是大模型版
2. 微信登录依赖服务端已正确配置 `WECHAT_MINI_APPID``WECHAT_MINI_SECRET`
3. 当前未实现文件音频上传,只实现了“转写文本写回后端”的数据链路
3. 分享读取接口为公开接口,建议前端仅用于只读展示