WebMusic/webmusic-server/README-MUSIC.md

83 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 音乐服务后端说明
## 功能说明
本后端实现了以下功能:
1. **歌曲搜索** - 支持搜索歌曲结果缓存在内存中5分钟过期
2. **播放队列管理** - 支持添加、移除、清空播放队列,队列数据存储在内存中
3. **歌曲详情** - 获取歌曲详情结果缓存在内存中10分钟过期
4. **歌曲播放URL** - 获取歌曲播放链接
## API接口
### 1. 搜索歌曲
```
GET /api/music/search?keywords=关键词&limit=20
```
### 2. 获取歌曲详情
```
GET /api/music/song/:id/detail
```
### 3. 获取歌曲播放URL
```
GET /api/music/song/:id/url?level=standard
```
### 4. 获取播放队列
```
GET /api/music/queue
```
### 5. 添加到播放队列
```
POST /api/music/queue/add
Body: { "song": { "id": "123", "title": "歌曲名", ... } }
```
### 6. 播放下一首(从队列取出)
```
POST /api/music/queue/play-next
```
### 7. 清空队列
```
POST /api/music/queue/clear
```
### 8. 从队列移除歌曲
```
POST /api/music/queue/remove
Body: { "songId": "123" }
```
## 配置
### 环境变量
- `NETEASE_API_BASE`: 网易云API服务器地址默认为 `http://localhost:3000`
### 端口
后端服务运行在 `7001` 端口(可在 `src/config/config.default.ts` 中修改)
## 启动
```bash
# 开发模式
npm run dev
# 生产模式
npm run build
npm start
```
## 注意事项
1. 所有缓存数据存储在内存中,服务重启后数据会丢失
2. 确保网易云API服务器api-enhanced正在运行在 3000 端口
3. 前端需要配置 `VITE_BACKEND_API` 环境变量指向后端地址(默认 `http://localhost:7001`