release nouri 0.6.0 polish backup and pwa

This commit is contained in:
2026-04-12 17:46:18 +02:00
parent 9ff7a6d57c
commit 555fddab80
31 changed files with 1257 additions and 164 deletions
+36 -27
View File
@@ -1,15 +1,32 @@
const CACHE_NAME = "nouri-v0-5-1-1";
const CACHE_NAME = "nouri-v0-6-0";
const OFFLINE_URL = "/static/pwa/offline.html";
const STATIC_ASSETS = [
"/static/css/styles.css",
"/static/js/theme.js",
"/static/js/ui.js",
"/static/js/planner.js",
"/static/js/pwa.js",
"/static/brand/pwa-180.png",
"/static/brand/pwa-192.png",
"/static/brand/pwa-512.png",
"/static/brand/pwa-maskable-512.png",
"/static/brand/pwa-badge.png",
"/static/brand/favicon.svg",
"/app.webmanifest",
OFFLINE_URL,
];
const cacheFirst = async (request) => {
const cached = await caches.match(request);
if (cached) return cached;
const response = await fetch(request);
if (response && response.ok && response.type === "basic") {
const cache = await caches.open(CACHE_NAME);
cache.put(request, response.clone());
}
return response;
};
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS)).then(() => self.skipWaiting())
@@ -28,40 +45,32 @@ self.addEventListener("fetch", (event) => {
if (event.request.method !== "GET") return;
const requestUrl = new URL(event.request.url);
const isStaticAsset =
requestUrl.origin === self.location.origin &&
(
requestUrl.pathname.startsWith("/static/")
|| requestUrl.pathname === "/app.webmanifest"
|| requestUrl.pathname === "/service-worker.js"
);
const isSameOrigin = requestUrl.origin === self.location.origin;
const isStaticAsset = isSameOrigin && (
requestUrl.pathname.startsWith("/static/")
|| requestUrl.pathname === "/app.webmanifest"
|| requestUrl.pathname === "/service-worker.js"
);
const isUpload = isSameOrigin && requestUrl.pathname.startsWith("/uploads/");
if (event.request.mode === "navigate") {
event.respondWith(
fetch(event.request).catch(() => caches.match(event.request))
fetch(event.request)
.then((response) => {
const copy = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, copy));
return response;
})
.catch(async () => {
return (await caches.match(event.request)) || caches.match(OFFLINE_URL);
})
);
return;
}
if (!isStaticAsset) {
return;
if (isStaticAsset || isUpload) {
event.respondWith(cacheFirst(event.request));
}
event.respondWith(
caches.match(event.request).then((cached) => {
if (cached) {
return cached;
}
return fetch(event.request).then((response) => {
if (!response || response.status !== 200 || response.type !== "basic") {
return response;
}
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
return response;
});
})
);
});
self.addEventListener("push", (event) => {