Skip to content

Commit 76e55d4

Browse files
committed
🐞 fix: 修复歌曲播放地址缓存导致播放失败问题 添加过期时间
1 parent b7de5fc commit 76e55d4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/renderer/store/modules/player.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@ const getSongDetail = async (playMusic: SongResult) => {
153153
return { ...playMusic, backgroundColor, primaryColor } as SongResult;
154154
}
155155

156+
if (playMusic.expiredAt && playMusic.expiredAt < Date.now()) {
157+
console.info(`歌曲已过期,重新获取: ${playMusic.name}`);
158+
playMusic.playMusicUrl = undefined;
159+
}
160+
156161
const playMusicUrl = playMusic.playMusicUrl || (await getSongUrl(playMusic.id, playMusic));
162+
playMusic.createdAt = Date.now();
163+
// 半小时后过期
164+
playMusic.expiredAt = playMusic.createdAt + 1800000;
157165
const { backgroundColor, primaryColor } =
158166
playMusic.backgroundColor && playMusic.primaryColor
159167
? playMusic

src/renderer/type/music.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface SongResult {
3838
cid: number;
3939
};
4040
source?: 'netease' | 'bilibili';
41+
// 过期时间
42+
expiredAt?: number;
43+
// 获取时间
44+
createdAt?: number;
4145
}
4246

4347
export interface Song {

0 commit comments

Comments
 (0)