Fix cache detection for tracks with spaces in filenames
Hunter
Sunday, November 9th, 2025 at 9:23 PM
47 let cachedTracks = new Set(); // Track which songs are cached for offline use
48 let CACHE_NAME = null; // Will be loaded from manifest.json
49
-// Load cache name from manifest.json first
50 +// Load cache name from manifest.json first, then load tracks
51 fetch('manifest.json')
52 .then(response => response.json())
53 .then(manifest => {
54 CACHE_NAME = manifest.cache_name || manifest.name;
55 console.log('Using cache name:', CACHE_NAME);
- })
- .catch(error => {
- console.error('Error loading manifest:', error);
- updateCurrentSongDisplay('Failed to load app configuration');
- });
56
-// Load tracks from tracks.json
-fetch('tracks.json')
57 + // Now that we have CACHE_NAME, load tracks
58 + return fetch('tracks.json');
59 + })
60 .then(response => {
61 if (!response.ok) {
62 throw new Error('tracks.json not found');
81 }
82 })
83 .catch(error => {
- console.error('Error loading tracks:', error);
84 + console.error('Error loading manifest or tracks:', error);
85 updateCurrentSongDisplay('Unable to load tracks. Please check your connection.');
86 });
87
923
924 // Check each song to see if it's cached
925 for (const song of songs) {
- const trackUrl = `tracks/${song.filename}`;
- const isInCache = cachedRequests.some(request => request.url.endsWith(trackUrl));
926 + // Build the same absolute URL that storeBlobInCache uses for consistency
927 + const absoluteUrl = new URL(`tracks/${song.filename}`, window.location.href).href;
928 + const isInCache = cachedRequests.some(request => request.url === absoluteUrl);
929 if (isInCache) {
930 cachedTracks.add(song.filename);
931 }