- web: BookPage/ReaderPage enrichis, sauvegarde de progression lecteur - web: locators EPUB/PDF normalisés (+ tests), EpubReader/PdfReader ajustés - web: nginx et service worker ajustés - api: progress — corrections contrôleur/service Refs: #13
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
const CACHE_NAME = "readabook-shell-v2";
|
|
const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/icons/readabook.svg"];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) => Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))))
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const url = new URL(event.request.url);
|
|
if (event.request.method !== "GET" || ["/auth", "/admin", "/books", "/progress"].some((path) => url.pathname.startsWith(path))) {
|
|
return;
|
|
}
|
|
if (event.request.mode === "navigate") {
|
|
event.respondWith(
|
|
fetch(event.request)
|
|
.then((response) => {
|
|
const copy = response.clone();
|
|
caches.open(CACHE_NAME).then((cache) => cache.put("/index.html", copy));
|
|
return response;
|
|
})
|
|
.catch(() => caches.match("/index.html").then((hit) => hit || caches.match("/")))
|
|
);
|
|
return;
|
|
}
|
|
event.respondWith(
|
|
caches.match(event.request).then((hit) => hit || fetch(event.request))
|
|
);
|
|
});
|