feat(music): 添加自动解析 并修改获取url的逻辑

This commit is contained in:
alger
2023-12-20 15:53:33 +08:00
parent bb1b07e0b3
commit a1780bc9d4
5 changed files with 36 additions and 55 deletions
+16 -8
View File
@@ -1,7 +1,8 @@
import { createStore } from "vuex";
import { SongResult } from "@/type/music";
import { getMusicUrl } from "@/api/music";
import homeRouter from "@/router/home";
import { getMusicUrl, getParsingMusicUrl } from '@/api/music'
import homeRouter from '@/router/home'
import { getMusicProxyUrl } from '@/hooks/MusicHook'
interface State {
menus: any[]
@@ -56,15 +57,22 @@ const mutations = {
}
const getSongUrl = async (id: number) => {
const { data } = await getMusicUrl(id);
console.log(data.data[0].url);
return data.data[0].url;
};
const { data } = await getMusicUrl(id)
try {
if (data.data[0].freeTrialInfo) {
const res = await getParsingMusicUrl(id)
return res.data.data.url
}
} catch (error) {
console.error('error', error)
}
return data.data[0].url
}
const updatePlayMusic = async (state: State) => {
state.playMusic = state.playList[state.playListIndex]
state.playMusicUrl = await getSongUrl(state.playMusic.id)
const playMusicUrl = await getSongUrl(state.playMusic.id)
state.playMusicUrl = getMusicProxyUrl(playMusicUrl)
state.play = true
}