feat: add cache to the getCoverArt endpoint, avoid it being reloaded every single time in the UI
This commit is contained in:
@@ -39,6 +39,7 @@ func (c *MediaRetrievalController) GetCoverArt(w http.ResponseWriter, r *http.Re
|
|||||||
}
|
}
|
||||||
size := utils.ParamInt(r, "size", 0)
|
size := utils.ParamInt(r, "size", 0)
|
||||||
|
|
||||||
|
w.Header().Set("cache-control", "public, max-age=300")
|
||||||
err = c.cover.Get(r.Context(), id, size, w)
|
err = c.cover.Get(r.Context(), id, size, w)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -20,11 +20,9 @@ const AlbumDetails = ({ classes, record }) => {
|
|||||||
return (
|
return (
|
||||||
<Card className={classes.container}>
|
<Card className={classes.container}>
|
||||||
<CardMedia
|
<CardMedia
|
||||||
image={subsonicUrl(
|
image={subsonicUrl('getCoverArt', record.coverArtId || 'not_found', {
|
||||||
'getCoverArt',
|
size: 500
|
||||||
record.coverArtId || 'not_found',
|
})}
|
||||||
'size=500'
|
|
||||||
)}
|
|
||||||
className={classes.albumCover}
|
className={classes.albumCover}
|
||||||
/>
|
/>
|
||||||
<CardContent className={classes.albumDetails}>
|
<CardContent className={classes.albumDetails}>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ const PLAYER_PLAY_ALBUM = 'PLAYER_PLAY_ALBUM'
|
|||||||
const mapToAudioLists = (item) => ({
|
const mapToAudioLists = (item) => ({
|
||||||
name: item.title,
|
name: item.title,
|
||||||
singer: item.artist,
|
singer: item.artist,
|
||||||
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
|
cover: subsonicUrl('getCoverArt', item.id, { size: 300 }),
|
||||||
musicSrc: subsonicUrl('stream', item.id),
|
musicSrc: subsonicUrl('stream', item.id, { ts: true }),
|
||||||
scrobble: (submit) => subsonicUrl('scrobble', item.id, `submission=${submit}`)
|
scrobble: (submit) => subsonicUrl('scrobble', item.id, { submission: submit })
|
||||||
})
|
})
|
||||||
|
|
||||||
const addTrack = (data) => ({
|
const addTrack = (data) => ({
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
const subsonicUrl = (command, id, options) => {
|
const subsonicUrl = (command, id, options) => {
|
||||||
const username = localStorage.getItem('username')
|
const params = new URLSearchParams()
|
||||||
const token = localStorage.getItem('subsonic-token')
|
params.append('u', localStorage.getItem('username'))
|
||||||
const salt = localStorage.getItem('subsonic-salt')
|
params.append('t', localStorage.getItem('subsonic-token'))
|
||||||
const timeStamp = new Date().getTime()
|
params.append('s', localStorage.getItem('subsonic-salt'))
|
||||||
const url = `rest/${command}?u=${username}&f=json&v=1.8.0&c=NavidromeUI&t=${token}&s=${salt}&id=${id}&_=${timeStamp}`
|
params.append('f', 'json')
|
||||||
|
params.append('v', '1.8.0')
|
||||||
|
params.append('c', 'NavidromeUI')
|
||||||
|
params.append('id', id)
|
||||||
if (options) {
|
if (options) {
|
||||||
return url + '&' + options
|
if (options.ts) {
|
||||||
|
options['_'] = new Date().getTime()
|
||||||
|
delete options.ts
|
||||||
}
|
}
|
||||||
return url
|
Object.keys(options).forEach((k) => {
|
||||||
|
params.append(k, options[k])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return `rest/${command}?${params.toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export { subsonicUrl }
|
export { subsonicUrl }
|
||||||
|
|||||||
Reference in New Issue
Block a user