mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-24 08:07:23 +08:00
✨ feat: 添加歌词缓存功能
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import store from '@/store';
|
||||
import { ILyric } from '@/type/lyric';
|
||||
import type { ILyric } from '@/type/lyric';
|
||||
import { isElectron } from '@/utils';
|
||||
import request from '@/utils/request';
|
||||
import requestMusic from '@/utils/request_music';
|
||||
@@ -36,8 +36,25 @@ export const getMusicDetail = (ids: Array<number>) => {
|
||||
};
|
||||
|
||||
// 根据音乐Id获取音乐歌词
|
||||
export const getMusicLrc = (id: number) => {
|
||||
return request.get<ILyric>('/lyric', { params: { id } });
|
||||
export const getMusicLrc = async (id: number) => {
|
||||
if (isElectron) {
|
||||
// 先尝试从缓存获取
|
||||
const cachedLyric = await window.api.invoke('get-cached-lyric', id);
|
||||
console.log('cachedLyric', cachedLyric);
|
||||
if (cachedLyric) {
|
||||
return { data: cachedLyric };
|
||||
}
|
||||
}
|
||||
|
||||
// 如果缓存中没有,则从服务器获取
|
||||
const res = await request.get<ILyric>('/lyric', { params: { id } });
|
||||
|
||||
// 缓存完整的响应数据
|
||||
if (isElectron && res) {
|
||||
await window.api.invoke('cache-lyric', id, res.data);
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getParsingMusicUrl = (id: number, data: any) => {
|
||||
|
||||
@@ -13,13 +13,11 @@ const musicHistory = useMusicHistory();
|
||||
// 获取歌曲url
|
||||
export const getSongUrl = async (id: number, songData: any, isDownloaded: boolean = false) => {
|
||||
const { data } = await getMusicUrl(id);
|
||||
console.log('data', data);
|
||||
let url = '';
|
||||
let songDetail = null;
|
||||
try {
|
||||
if (data.data[0].freeTrialInfo || !data.data[0].url) {
|
||||
const res = await getParsingMusicUrl(id, songData);
|
||||
console.log('res', res);
|
||||
url = res.data.data.url;
|
||||
songDetail = res.data.data;
|
||||
} else {
|
||||
@@ -52,7 +50,6 @@ const getSongDetail = async (playMusic: SongResult) => {
|
||||
export const useMusicListHook = () => {
|
||||
const handlePlayMusic = async (state: any, playMusic: SongResult) => {
|
||||
const updatedPlayMusic = await getSongDetail(playMusic);
|
||||
console.log('updatedPlayMusic', updatedPlayMusic);
|
||||
state.playMusic = updatedPlayMusic;
|
||||
state.playMusicUrl = updatedPlayMusic.playMusicUrl;
|
||||
state.play = true;
|
||||
|
||||
@@ -552,7 +552,8 @@ const clearCacheOptions = ref([
|
||||
{ label: '用户数据', key: 'user', description: '清除登录信息和用户相关数据' },
|
||||
{ label: '应用设置', key: 'settings', description: '清除应用的所有自定义设置' },
|
||||
{ label: '下载记录', key: 'downloads', description: '清除下载历史记录(不会删除已下载的文件)' },
|
||||
{ label: '音乐资源', key: 'resources', description: '清除已加载的音乐文件、歌词等资源缓存' }
|
||||
{ label: '音乐资源', key: 'resources', description: '清除已加载的音乐文件、歌词等资源缓存' },
|
||||
{ label: '歌词资源', key: 'lyrics', description: '清除已加载的歌词资源缓存' }
|
||||
]);
|
||||
|
||||
const selectedCacheTypes = ref<string[]>([]);
|
||||
@@ -609,6 +610,9 @@ const clearCache = async () => {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'lyrics':
|
||||
window.api.invoke('clear-lyrics-cache');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user