- Add LICENSE file (CC BY-NC-SA 4.0) - Add .nvmrc pinning Node 22 - Add Renovate config with daily schedule and Gitea Actions workflow - Reduce ESLint max-warnings from 1000 to 50 - Re-enable Biome a11y/security recommended rules - Fix Biome lint issues (a11y, hook deps, SVG labels, checkbox semantics) - Improve CI: run on pushes to feat/fix branches, add pnpm audit - Add Vitest coverage with v8 provider and thresholds - Add E2E tests (auth, admin, navigation specs) - Add admin-maintenance server action test - Install @vitest/coverage-v8 - Ignore coverage/ directory
68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
const CACHE = "atom-v3";
|
|
const API_CACHE = "atom-api-v3";
|
|
|
|
self.addEventListener("install", () => self.skipWaiting());
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches
|
|
.keys()
|
|
.then((keys) =>
|
|
Promise.all(
|
|
keys
|
|
.filter((k) => k !== CACHE && k !== API_CACHE)
|
|
.map((k) => caches.delete(k)),
|
|
),
|
|
)
|
|
.then(() => self.clients.claim()),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const req = event.request;
|
|
if (req.method !== "GET") return;
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return;
|
|
|
|
if (
|
|
url.pathname.startsWith("/assets/") ||
|
|
url.pathname.startsWith("/_next/static/")
|
|
) {
|
|
event.respondWith(
|
|
caches.open(CACHE).then((cache) =>
|
|
cache.match(req).then(
|
|
(hit) =>
|
|
hit ||
|
|
fetch(req).then((res) => {
|
|
if (res.ok) cache.put(req, res.clone());
|
|
return res;
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (
|
|
url.pathname.startsWith("/api/home") ||
|
|
url.pathname.startsWith("/api/online") ||
|
|
url.pathname.startsWith("/api/radio/config")
|
|
) {
|
|
event.respondWith(
|
|
caches.open(API_CACHE).then((cache) =>
|
|
fetch(req)
|
|
.then((res) => {
|
|
if (res.ok) cache.put(req, res.clone());
|
|
return res;
|
|
})
|
|
.catch(() => cache.match(req)),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (req.mode === "navigate") {
|
|
event.respondWith(fetch(req));
|
|
}
|
|
});
|