A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: use cached entry from file tree in service worker

+10 -3
+10 -3
src/service-worker-offline.js
··· 152 152 //////////////////////////////////////////// 153 153 154 154 /** 155 - * Network-first strategy with content-addressed caching. 155 + * Cache-first for file-tree entries, network-first for everything else. 156 156 * 157 - * Online → fetch from network, store response by CID, return it. 158 - * Offline → resolve the URL through the index, serve by CID from the content cache. 157 + * Online + in file tree → serve from cache if present, otherwise fetch and store. 158 + * Online + not in tree → fetch from network, store response by CID, return it. 159 + * Offline → resolve the URL through the index, serve by CID from the content cache. 159 160 * 160 161 * Partial responses (206) are passed through without caching so that 161 162 * range requests for audio streaming work as normal. ··· 165 166 */ 166 167 async function handleFetch(request) { 167 168 if (navigator.onLine) { 169 + const { pathname } = new URL(request.url); 170 + if (await cidFromTree(pathname) !== undefined) { 171 + const cached = await lookup(request); 172 + if (cached) return cached; 173 + } 174 + 168 175 try { 169 176 return await fetchAndStore(request); 170 177 } catch {}