Fix playback of some token protected resources

This commit is contained in:
wvffle 2022-10-29 06:09:07 +00:00 committed by Georg Krause
parent 4cd7ca2cb4
commit 3ae5adc7ba
No known key found for this signature in database
GPG Key ID: 2970D504B2183D22
1 changed files with 12 additions and 1 deletions

View File

@ -19,10 +19,21 @@ const soundPromises = new Map<number, Promise<Sound>>()
const soundCache = useLRUCache<number, Sound>({ max: 10 }) const soundCache = useLRUCache<number, Sound>({ max: 10 })
const getTrackSources = (track: QueueTrack): QueueTrackSource[] => { const getTrackSources = (track: QueueTrack): QueueTrackSource[] => {
const token = store.state.auth.authenticated && store.state.auth.scopedTokens.listen
const appendToken = (url: string) => {
if (token) {
const newUrl = new URL(url)
newUrl.searchParams.set('token', token)
return newUrl.toString()
}
return url
}
const sources: QueueTrackSource[] = track.sources const sources: QueueTrackSource[] = track.sources
.map((source) => ({ .map((source) => ({
...source, ...source,
url: store.getters['instance/absoluteUrl'](source.url) as string url: appendToken(store.getters['instance/absoluteUrl'](source.url))
})) }))
// NOTE: Add a transcoded MP3 src at the end for browsers // NOTE: Add a transcoded MP3 src at the end for browsers