- Implement gPodder API v2 compatible endpoints at /api/2/: - Auth: login/logout via HTTP Basic Auth or session - Devices: list and register sync devices - Subscriptions: get/add/remove per device, delta sync with ?since= - Episode actions: upload play/position events, syncs to EpisodeProgress - Server URL for AntennaPod: https://diora.creamfresh.xyz/api/2/ - Bump SW cache diora-v4 → v5 to force re-fetch of updated app.js Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
/**
|
|
* diora service worker — caches the app shell for offline use.
|
|
*/
|
|
|
|
const CACHE = 'diora-v5';
|
|
const PODCAST_CACHE = 'diora-podcast-v1';
|
|
const SHELL = [
|
|
'/static/css/app.css',
|
|
'/static/js/app.js',
|
|
'/static/manifest.json',
|
|
];
|
|
|
|
// Install: pre-cache the app shell
|
|
self.addEventListener('install', function (event) {
|
|
event.waitUntil(
|
|
caches.open(CACHE).then(function (cache) {
|
|
return cache.addAll(SHELL);
|
|
})
|
|
);
|
|
// Activate immediately without waiting for old tabs to close
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// Activate: remove stale caches from previous versions
|
|
self.addEventListener('activate', function (event) {
|
|
event.waitUntil(
|
|
caches.keys().then(function (keys) {
|
|
return Promise.all(
|
|
keys.filter(function (key) { return key !== CACHE && key !== PODCAST_CACHE; })
|
|
.map(function (key) { return caches.delete(key); })
|
|
);
|
|
}).then(function () {
|
|
return self.clients.claim();
|
|
})
|
|
);
|
|
});
|
|
|
|
// Fetch: serve from cache, fall back to network
|
|
self.addEventListener('fetch', function (event) {
|
|
// Only handle GET requests; let POST/SSE etc. pass through
|
|
if (event.request.method !== 'GET') return;
|
|
|
|
const url = new URL(event.request.url);
|
|
|
|
// Bypass for API/mutation endpoints
|
|
if (url.pathname.startsWith('/radio/sse/') ||
|
|
url.pathname.startsWith('/radio/record/') ||
|
|
url.pathname.startsWith('/radio/affiliate/') ||
|
|
url.pathname.startsWith('/admin/') ||
|
|
url.pathname.startsWith('/podcasts/progress/') ||
|
|
url.pathname.startsWith('/podcasts/queue/') ||
|
|
url.pathname === '/podcasts/feeds/add' ||
|
|
url.pathname.startsWith('/podcasts/feeds/add') ||
|
|
url.pathname.includes('/remove') ||
|
|
url.pathname.startsWith('/podcasts/feeds/refresh')) {
|
|
return;
|
|
}
|
|
|
|
// Podcast audio: serve from podcast cache first, then network
|
|
if (event.request.destination === 'audio') {
|
|
event.respondWith(
|
|
caches.open(PODCAST_CACHE).then(function (cache) {
|
|
return cache.match(event.request).then(function (cached) {
|
|
if (cached) return cached;
|
|
return fetch(event.request).then(function (response) {
|
|
return response;
|
|
});
|
|
});
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Cache-first only for pre-defined shell assets; everything else hits the network
|
|
const isShell = SHELL.some(function (s) { return url.pathname === s; });
|
|
if (isShell) {
|
|
event.respondWith(
|
|
caches.match(event.request).then(function (cached) {
|
|
return cached || fetch(event.request);
|
|
})
|
|
);
|
|
}
|
|
});
|