feat: add cache to the getCoverArt endpoint, avoid it being reloaded every single time in the UI

This commit is contained in:
Deluan 2020-02-15 14:20:04 -05:00
parent 272d897ec9
commit 3b12c92ad5
4 changed files with 23 additions and 15 deletions

View File

@ -39,6 +39,7 @@ func (c *MediaRetrievalController) GetCoverArt(w http.ResponseWriter, r *http.Re
}
size := utils.ParamInt(r, "size", 0)
w.Header().Set("cache-control", "public, max-age=300")
err = c.cover.Get(r.Context(), id, size, w)
switch {

View File

@ -20,11 +20,9 @@ const AlbumDetails = ({ classes, record }) => {
return (
<Card className={classes.container}>
<CardMedia
image={subsonicUrl(
'getCoverArt',
record.coverArtId || 'not_found',
'size=500'
)}
image={subsonicUrl('getCoverArt', record.coverArtId || 'not_found', {
size: 500
})}
className={classes.albumCover}
/>
<CardContent className={classes.albumDetails}>

View File

@ -10,9 +10,9 @@ const PLAYER_PLAY_ALBUM = 'PLAYER_PLAY_ALBUM'
const mapToAudioLists = (item) => ({
name: item.title,
singer: item.artist,
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
musicSrc: subsonicUrl('stream', item.id),
scrobble: (submit) => subsonicUrl('scrobble', item.id, `submission=${submit}`)
cover: subsonicUrl('getCoverArt', item.id, { size: 300 }),
musicSrc: subsonicUrl('stream', item.id, { ts: true }),
scrobble: (submit) => subsonicUrl('scrobble', item.id, { submission: submit })
})
const addTrack = (data) => ({

View File

@ -1,13 +1,22 @@
const subsonicUrl = (command, id, options) => {
const username = localStorage.getItem('username')
const token = localStorage.getItem('subsonic-token')
const salt = localStorage.getItem('subsonic-salt')
const timeStamp = new Date().getTime()
const url = `rest/${command}?u=${username}&f=json&v=1.8.0&c=NavidromeUI&t=${token}&s=${salt}&id=${id}&_=${timeStamp}`
const params = new URLSearchParams()
params.append('u', localStorage.getItem('username'))
params.append('t', localStorage.getItem('subsonic-token'))
params.append('s', localStorage.getItem('subsonic-salt'))
params.append('f', 'json')
params.append('v', '1.8.0')
params.append('c', 'NavidromeUI')
params.append('id', id)
if (options) {
return url + '&' + options
if (options.ts) {
options['_'] = new Date().getTime()
delete options.ts
}
Object.keys(options).forEach((k) => {
params.append(k, options[k])
})
}
return url
return `rest/${command}?${params.toString()}`
}
export { subsonicUrl }