Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 为“云盘歌曲(pc)”补充在线歌词获取能力:优先从云盘歌词接口拉取,并在 Electron 缓存开启时按“用户维度”隔离缓存,避免不同账号间歌词串用。
Changes:
- 新增云盘歌词 API:
/cloud/lyric/get - 在线歌词获取逻辑中:云盘歌曲优先走云盘歌词接口,并引入
cloud_${userId}_${id}缓存 key - 增强歌词字段兼容:支持歌词字段为 string 或
{ lyric: string }两种形态
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/core/player/LyricManager.ts | 云盘歌词优先获取 + 用户隔离缓存 key + 更健壮的歌词字段读取 |
| src/api/cloud.ts | 新增云盘歌词请求封装 cloudSongLyric |
| if (!data) { | ||
| data = await songLyric(id); | ||
| if (song.pc && userId) { | ||
| data = await cloudSongLyric(id, userId); | ||
| } | ||
| if (!data) { | ||
| data = await songLyric(id); | ||
| } | ||
| if (data && data.code === 200) { | ||
| this.saveRawLyricCache(id, "lrc", JSON.stringify(data)); | ||
| this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data)); | ||
| } | ||
| } | ||
| if (!data || data.code !== 200) return; |
There was a problem hiding this comment.
当 song.pc && userId 时会先请求 cloudSongLyric,但当前逻辑只有在 data 为 falsy 时才回退到 songLyric。若 cloudSongLyric 返回了一个非 200 的响应对象(例如 { code: 4xx }),这里会直接 return 导致整首歌没有歌词;建议在 cloudSongLyric 结果为空“或 code !== 200”时都回退到 songLyric,再统一做 code 校验与缓存写入。
| export const cloudSongLyric = (sid: number, uid: number) => { | ||
| return request({ | ||
| url: "/cloud/lyric/get", | ||
| params: { | ||
| sid, | ||
| uid, |
There was a problem hiding this comment.
cloudSongLyric 的参数顺序是 (sid, uid),但同文件的 matchCloudSong 是 (uid, sid, asid)。这种不一致很容易在后续调用时传参写反;建议统一为 (uid, sid) 或改为接收一个对象参数(如 { uid, sid })以提升可读性并减少误用风险。
| export const cloudSongLyric = (sid: number, uid: number) => { | |
| return request({ | |
| url: "/cloud/lyric/get", | |
| params: { | |
| sid, | |
| uid, | |
| export const cloudSongLyric = (uid: number, sid: number) => { | |
| return request({ | |
| url: "/cloud/lyric/get", | |
| params: { | |
| uid, | |
| sid, |
There was a problem hiding this comment.
Code Review
This pull request introduces support for fetching and caching cloud song lyrics by adding a new API endpoint and updating the LyricManager. Key changes include the implementation of a user-specific cache key for cloud songs and a helper function to standardize lyric text extraction from various data formats. A bug was identified in the lyric fetching logic where a non-200 response from the cloud API would incorrectly block the fallback to standard lyrics; a suggestion has been provided to ensure the fallback occurs whenever a successful cloud lyric response is not received.
| if (!data) { | ||
| data = await songLyric(id); | ||
| if (song.pc && userId) { | ||
| data = await cloudSongLyric(id, userId); | ||
| } | ||
| if (!data) { | ||
| data = await songLyric(id); | ||
| } | ||
| if (data && data.code === 200) { | ||
| this.saveRawLyricCache(id, "lrc", JSON.stringify(data)); | ||
| this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data)); | ||
| } | ||
| } |
There was a problem hiding this comment.
The fallback logic for cloud song lyrics is incorrect. If cloudSongLyric returns a response object with a non-200 code (e.g., 404), the current implementation will skip the call to songLyric(id) because data is already truthy. This prevents the application from falling back to standard lyrics for cloud songs that might be matched in the library but don't have cloud-specific lyrics available in the cloud API.
| if (!data) { | |
| data = await songLyric(id); | |
| if (song.pc && userId) { | |
| data = await cloudSongLyric(id, userId); | |
| } | |
| if (!data) { | |
| data = await songLyric(id); | |
| } | |
| if (data && data.code === 200) { | |
| this.saveRawLyricCache(id, "lrc", JSON.stringify(data)); | |
| this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data)); | |
| } | |
| } | |
| if (!data) { | |
| if (song.pc && userId) { | |
| data = await cloudSongLyric(id, userId); | |
| } | |
| if (!data || data.code !== 200) { | |
| data = await songLyric(id); | |
| } | |
| if (data && data.code === 200) { | |
| this.saveRawLyricCache(lyricCacheKey, "lrc", JSON.stringify(data)); | |
| } | |
| } |
效果
