mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
feat: updates
This commit is contained in:
parent
196a974a64
commit
8f4c3d8e5b
24 changed files with 572 additions and 93 deletions
43
packages/web/hooks/useVideoCover.ts
Normal file
43
packages/web/hooks/useVideoCover.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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,
|
||||
}
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue