2022-06-12 15:29:14 +08:00
|
|
|
import axios from 'axios'
|
2022-08-03 23:48:39 +08:00
|
|
|
import { useQuery } from '@tanstack/react-query'
|
2023-01-07 14:39:03 +08:00
|
|
|
import { appName } from '../utils/const'
|
2022-06-12 15:29:14 +08:00
|
|
|
|
|
|
|
export default function useVideoCover(props: {
|
|
|
|
id?: number
|
|
|
|
name?: string
|
|
|
|
artist?: string
|
2022-07-12 22:42:50 +08:00
|
|
|
enabled?: boolean
|
2022-06-12 15:29:14 +08:00
|
|
|
}) {
|
2022-07-12 22:42:50 +08:00
|
|
|
const { id, name, artist, enabled = true } = props
|
2022-06-12 15:29:14 +08:00
|
|
|
return useQuery(
|
|
|
|
['useVideoCover', props],
|
|
|
|
async () => {
|
|
|
|
if (!id || !name || !artist) return
|
|
|
|
|
2023-01-07 14:39:03 +08:00
|
|
|
const fromRemote = await axios.get(
|
|
|
|
`/${appName.toLowerCase()}/video-cover`,
|
|
|
|
{
|
|
|
|
params: props,
|
|
|
|
}
|
|
|
|
)
|
2022-06-12 15:29:14 +08:00
|
|
|
if (fromRemote?.data?.url) {
|
|
|
|
return fromRemote.data.url
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-07-12 22:42:50 +08:00
|
|
|
enabled: !!id && !!name && !!artist && enabled,
|
2022-06-12 15:29:14 +08:00
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
refetchInterval: false,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|