import { cache, httpService } from '@/services' import { albumStore, artistStore, songStore } from '@/stores' export const mediaInfoService = { async fetchForArtist (artist: Artist) { artist = artistStore.syncWithVault(artist)[0] const cacheKey = ['artist.info', artist.id] if (cache.has(cacheKey)) return cache.get(cacheKey) const info = await httpService.get(`artists/${artist.id}/information`) info && cache.set(cacheKey, info) info?.image && (artist.image = info.image) return info }, async fetchForAlbum (album: Album) { album = albumStore.syncWithVault(album)[0] const cacheKey = ['album.info', album.id] if (cache.has(cacheKey)) return cache.get(cacheKey) const info = await httpService.get(`albums/${album.id}/information`) info && cache.set(cacheKey, info) if (info?.cover) { album.cover = info.cover songStore.byAlbum(album).forEach(song => (song.album_cover = info.cover!)) } return info } }