mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 18:03:07 +02:00
- Move puzzle_solver/, poker_modifier_app/, articles/, tests/ into python_pkg/ - Move moviepy_showcase.py and _moviepy_*.py into python_pkg/moviepy_showcase/ - Update all imports to use python_pkg. prefix - Update pyproject.toml per-file-ignores and pytest testpaths - Add pre-commit hook to enforce Python files under python_pkg/
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
// Minimal image cache-first service worker
|
|
const C = 'articles-img-v2';
|
|
const AC = 'articles-json-v1';
|
|
self.addEventListener('install', e => self.skipWaiting());
|
|
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
|
|
self.addEventListener('fetch', e => {
|
|
const req = e.request;
|
|
if (req.method !== 'GET') return;
|
|
const u = new URL(req.url);
|
|
const isImg = req.destination === 'image' || u.pathname.startsWith('/uploads/');
|
|
const isArticle = u.pathname.startsWith('/api/articles/') && u.pathname.length > '/api/articles/'.length;
|
|
if (isImg) {
|
|
e.respondWith((async () => {
|
|
const cache = await caches.open(C);
|
|
const hit = await cache.match(req, { ignoreVary: true, ignoreSearch: false });
|
|
if (hit) return hit;
|
|
const res = await fetch(req);
|
|
if (res && res.ok) cache.put(req, res.clone());
|
|
return res;
|
|
})());
|
|
} else if (isArticle) {
|
|
e.respondWith((async () => {
|
|
const cache = await caches.open(AC);
|
|
const hit = await cache.match(req);
|
|
if (hit) return hit;
|
|
const res = await fetch(req);
|
|
if (res && res.ok) cache.put(req, res.clone());
|
|
return res;
|
|
})());
|
|
}
|
|
});
|