vamos
All checks were successful
build-and-deploy / build (push) Successful in 23s
build-and-deploy / deploy (push) Successful in 3s

This commit is contained in:
2025-10-12 00:59:50 -06:00
parent 1f087eb6f3
commit 98fb972a4e
4 changed files with 173 additions and 34 deletions

View File

@@ -166,9 +166,20 @@ const playTrack = async (track, index) => {
// Fetch and preload entire song into memory
const encodedName = encodeURIComponent(track.name)
const response = await fetch(`/api/music/${encodedName}`)
// Check for authentication errors
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
const errorMsg = `HTTP ${response.status}`
// If auth error, propagate to music store for auth indicator to detect
if (response.status === 401 || response.status === 403) {
console.warn('[PlayTrack] Authentication error:', response.status)
musicStore.error = `${errorMsg}: Unauthorized - Please log in`
}
throw new Error(errorMsg)
}
const blob = await response.blob()
const audioUrl = URL.createObjectURL(blob)
@@ -186,16 +197,22 @@ const playTrack = async (track, index) => {
}, { once: true })
} catch (error) {
console.error('Failed to preload track:', error)
// Mark track as failed
failedTracks.value.add(track.name)
loadingTrack.value = null
// Don't try fallback streaming if it's an auth error (it will fail too)
if (error.message && (error.message.includes('401') || error.message.includes('403'))) {
console.warn('[PlayTrack] Skipping fallback due to auth error')
return
}
// Try fallback to streaming
const encodedName = encodeURIComponent(track.name)
audioPlayer.value.src = `/api/music/${encodedName}`
audioPlayer.value.load()
// Auto-play when ready (fallback)
audioPlayer.value.addEventListener('canplay', () => {
loadingTrack.value = null