mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-12-02 05:23:39 +08:00
44 lines
1021 B
TypeScript
44 lines
1021 B
TypeScript
import { IpcChannels } from '@/shared/IpcChannels'
|
|
import axios from 'axios'
|
|
import { useQuery } from 'react-query'
|
|
|
|
export default function useVideoCover(props: {
|
|
id?: number
|
|
name?: string
|
|
artist?: string
|
|
}) {
|
|
const { id, name, artist } = props
|
|
return useQuery(
|
|
['useVideoCover', props],
|
|
async () => {
|
|
if (!id || !name || !artist) return
|
|
|
|
const fromCache = window.ipcRenderer?.sendSync(
|
|
IpcChannels.GetVideoCover,
|
|
{
|
|
id,
|
|
}
|
|
)
|
|
if (fromCache) {
|
|
return fromCache === 'no' ? undefined : fromCache
|
|
}
|
|
|
|
const fromRemote = await axios.get('/yesplaymusic/video-cover', {
|
|
params: props,
|
|
})
|
|
window.ipcRenderer?.send(IpcChannels.SetVideoCover, {
|
|
id,
|
|
url: fromRemote.data.url || '',
|
|
})
|
|
if (fromRemote?.data?.url) {
|
|
return fromRemote.data.url
|
|
}
|
|
},
|
|
{
|
|
enabled: !!id && !!name && !!artist,
|
|
refetchOnWindowFocus: false,
|
|
refetchInterval: false,
|
|
}
|
|
)
|
|
}
|