- Backend: /api/compare Endpoint für Podcast-Vergleich (Stats, gemeinsame Topics, Top-Querverbindungen), /api/.../words Endpoint für Wort-Timestamps - Frontend: Podcast-Vergleichsansicht mit Statistiken und Cross-Links, Cross-Podcast-Suche-Toggle, semantische Links im Transkript (lazy-loaded), Podcast-Switcher mit Zurück-Navigation - PWA: manifest.json, Service Worker (stale-while-revalidate für Assets, network-first für API, cache-on-success für Audio), Icons - Scripts: transcribe_words.py (mlx-whisper Batch-Transkription mit Wort-Timestamps), import_words.py (Wort-Timestamps in DB importieren) - Dockerfile: PWA-Assets in Container kopieren Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
const CACHE_NAME = 'podcast-mindmap-v1';
|
|
|
|
// Core assets to cache immediately
|
|
const CORE_ASSETS = [
|
|
'/',
|
|
'/index.html',
|
|
'/d3.v7.min.js',
|
|
'/manifest.json'
|
|
];
|
|
|
|
// Install: cache core assets
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then(cache => cache.addAll(CORE_ASSETS))
|
|
.then(() => self.skipWaiting())
|
|
);
|
|
});
|
|
|
|
// Activate: clean old caches
|
|
self.addEventListener('activate', event => {
|
|
event.waitUntil(
|
|
caches.keys().then(keys =>
|
|
Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
|
|
).then(() => self.clients.claim())
|
|
);
|
|
});
|
|
|
|
// Fetch: network-first for API, cache-first for static assets
|
|
self.addEventListener('fetch', event => {
|
|
const url = new URL(event.request.url);
|
|
|
|
// Skip non-GET requests
|
|
if (event.request.method !== 'GET') return;
|
|
|
|
// API calls: network-first with no cache
|
|
if (url.pathname.startsWith('/api/')) {
|
|
event.respondWith(
|
|
fetch(event.request).catch(() =>
|
|
new Response(JSON.stringify({ error: 'offline' }), {
|
|
headers: { 'Content-Type': 'application/json' }
|
|
})
|
|
)
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Audio files: network-first, cache on success (optional offline playback)
|
|
if (url.pathname.startsWith('/audio/')) {
|
|
event.respondWith(
|
|
fetch(event.request).then(resp => {
|
|
// Only cache complete responses (not range requests)
|
|
if (resp.status === 200) {
|
|
const clone = resp.clone();
|
|
caches.open(CACHE_NAME).then(cache => cache.put(event.request, clone));
|
|
}
|
|
return resp;
|
|
}).catch(() => caches.match(event.request))
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Static assets + JSON data: stale-while-revalidate
|
|
event.respondWith(
|
|
caches.match(event.request).then(cached => {
|
|
const fetchPromise = fetch(event.request).then(resp => {
|
|
if (resp.ok) {
|
|
const clone = resp.clone();
|
|
caches.open(CACHE_NAME).then(cache => cache.put(event.request, clone));
|
|
}
|
|
return resp;
|
|
}).catch(() => cached);
|
|
|
|
return cached || fetchPromise;
|
|
})
|
|
);
|
|
});
|