mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 05:38:04 +00:00
feat: updates
This commit is contained in:
parent
222fb02355
commit
47e41dea9b
24 changed files with 380 additions and 130 deletions
26
packages/web/hooks/useAppleMusicAlbum.ts
Normal file
26
packages/web/hooks/useAppleMusicAlbum.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
export default function useAppleMusicAlbum(props: {
|
||||
id?: number
|
||||
name?: string
|
||||
artist?: string
|
||||
}) {
|
||||
const { id, name, artist } = props
|
||||
return useQuery(
|
||||
['useAppleMusicAlbum', props],
|
||||
async () => {
|
||||
if (!id || !name || !artist) return
|
||||
return window.ipcRenderer?.invoke(IpcChannels.GetAlbumFromAppleMusic, {
|
||||
id,
|
||||
name,
|
||||
artist,
|
||||
})
|
||||
},
|
||||
{
|
||||
enabled: !!id && !!name && !!artist,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchInterval: false,
|
||||
}
|
||||
)
|
||||
}
|
||||
33
packages/web/hooks/useAppleMusicArtist.ts
Normal file
33
packages/web/hooks/useAppleMusicArtist.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { AppleMusicArtist } from '@/shared/AppleMusic'
|
||||
import { APIs } from '@/shared/CacheAPIs'
|
||||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
export default function useAppleMusicArtist(props: {
|
||||
id?: number
|
||||
name?: string
|
||||
}) {
|
||||
const { id, name } = props
|
||||
return useQuery(
|
||||
['useAppleMusicArtist', props],
|
||||
async () => {
|
||||
if (!id || !name) return
|
||||
return window.ipcRenderer?.invoke(IpcChannels.GetArtistFromAppleMusic, {
|
||||
id,
|
||||
name,
|
||||
})
|
||||
},
|
||||
{
|
||||
enabled: !!id && !!name,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchInterval: false,
|
||||
initialData: (): AppleMusicArtist =>
|
||||
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
||||
api: APIs.AppleMusicArtist,
|
||||
query: {
|
||||
id,
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import { IpcChannels } from '@/shared/IpcChannels'
|
||||
import axios from 'axios'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
|
|
@ -6,25 +5,14 @@ export default function useVideoCover(props: {
|
|||
id?: number
|
||||
name?: string
|
||||
artist?: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const { id, name, artist } = props
|
||||
const { id, name, artist, enabled = true } = props
|
||||
return useQuery(
|
||||
['useVideoCover', props],
|
||||
async () => {
|
||||
if (!id || !name || !artist) return
|
||||
|
||||
const fromMainProcess = await window.ipcRenderer?.invoke(
|
||||
IpcChannels.GetVideoCover,
|
||||
{
|
||||
id,
|
||||
name,
|
||||
artist,
|
||||
}
|
||||
)
|
||||
if (fromMainProcess) {
|
||||
return fromMainProcess
|
||||
}
|
||||
|
||||
const fromRemote = await axios.get('/yesplaymusic/video-cover', {
|
||||
params: props,
|
||||
})
|
||||
|
|
@ -33,7 +21,7 @@ export default function useVideoCover(props: {
|
|||
}
|
||||
},
|
||||
{
|
||||
enabled: !!id && !!name && !!artist,
|
||||
enabled: !!id && !!name && !!artist && enabled,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchInterval: false,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue