mirror of
https://github.com/Dvorinka/Dash.git
synced 2026-10-28 07:41:27 +00:00
P5a: 24h uptime bar strip + latency chart on monitor detail, iframe
embed widget, generic JSON-path widget, accent/wallpaper/custom CSS
settings, PWA manifest + service worker, demo GIF.
P5b: transport picker + per-transport fields + test button in
settings; per-monitor alert-rule fields in dialogs.
P5c: container cpu/mem columns, SMART/ZFS/GPU sections on system
detail, subdomains section on domain detail.
P5d: login/setup page + auth middleware client handling, board
switcher + /b/:slug routes, full string extraction to typed t() keys
with {param} interpolation, complete cs locale, language select.
Authored By: TDvorak <[email protected]>
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
// Dash service worker: cache-first for static assets, network-first for /api.
|
|
// Bump CACHE on each deploy shape change; clients drop stale caches on activate.
|
|
const CACHE = "dash-v1";
|
|
const ASSET = /\.(?:js|css|woff2?|png|svg|webmanifest|ico)$/;
|
|
|
|
self.addEventListener("install", (e) => {
|
|
self.skipWaiting();
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.add("/")));
|
|
});
|
|
|
|
self.addEventListener("activate", (e) => {
|
|
e.waitUntil(
|
|
caches.keys()
|
|
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
|
.then(() => self.clients.claim()),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("fetch", (e) => {
|
|
const url = new URL(e.request.url);
|
|
if (e.request.method !== "GET" || url.origin !== self.location.origin) return;
|
|
|
|
// API: network-first so widgets stay live; fall back to cache offline.
|
|
if (url.pathname.startsWith("/api/")) {
|
|
e.respondWith(
|
|
fetch(e.request)
|
|
.then((res) => {
|
|
const clone = res.clone();
|
|
if (res.ok) caches.open(CACHE).then((c) => c.put(e.request, clone));
|
|
return res;
|
|
})
|
|
.catch(() => caches.match(e.request)),
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Navigations: network-first, fall back to cached "/" (read-only offline).
|
|
if (e.request.mode === "navigate") {
|
|
e.respondWith(fetch(e.request).catch(() => caches.match("/")));
|
|
return;
|
|
}
|
|
|
|
// Static assets: cache-first, populate on miss.
|
|
if (ASSET.test(url.pathname)) {
|
|
e.respondWith(
|
|
caches.match(e.request).then(
|
|
(hit) =>
|
|
hit ||
|
|
fetch(e.request).then((res) => {
|
|
const clone = res.clone();
|
|
if (res.ok) caches.open(CACHE).then((c) => c.put(e.request, clone));
|
|
return res;
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
});
|