Offline podcast episodes, Continue reading on Home, switch to turn off online lookups

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UaC9HmtHMdRP8dAbN4wAKj
This commit is contained in:
Claude committed 2026-10-26 11:52:16 +00:00
1 parent 95c9127e8e
commit 57edf974fd
10 files changed
+48 -5

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
'use strict';
// Save podcast episodes on this device, so they play with no signal. They live in the browser's own storage (a cache the service worker answers from),
// so they are not synced between devices, and the browser may clear them if the phone runs low on space.
const OFFLINE = 'hub-offline';
const offUrl = id => '/api/podcast/podcasts/' + encodeURIComponent(id) + '/file';
const offHas = async id => { try { return !!(await (await caches.open(OFFLINE)).match(offUrl(id))); } catch { return false; } };
async function offSave(id, onDone) {
if (!('caches' in window)) { toast('This browser cannot save for offline'); return; }
toast('Saving…');
try {
const r = await fetch(offUrl(id), { credentials: 'same-origin' }); if (!r.ok) throw new Error('Could not download (' + r.status + ')');
await (await caches.open(OFFLINE)).put(offUrl(id), r); toast('Saved on this device'); if (navigator.storage && navigator.storage.persist) navigator.storage.persist().catch(() => {});
} catch (e) { try { await (await caches.open(OFFLINE)).delete(offUrl(id)); } catch {} toast(e.message || 'Could not save'); }
if (onDone) onDone();
}
async function offRemove(id, onDone) { try { await (await caches.open(OFFLINE)).delete(offUrl(id)); toast('Removed from this device'); } catch {} if (onDone) onDone(); }