fe66575ffe
Login: add an in-memory per-IP throttle (8 failed attempts -> 15-min lockout, 429 + Retry-After), raise the change-password minimum to 8 with a 72-char cap, and apply the same minimum on the StartOS Set Login Password action. Records: add a record_floor column for manually-pinned bests plus recomputeRecord(); the live record is now the direction-aware best of the best logged value and the floor, recomputed on entry edit/delete so it can drop again (never below the floor). Settings exposes the floor as an override and shows the live best as a placeholder. Bump package 0.1.6:0 -> 0.1.7:0 and the service-worker cache to v7.
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const CACHE = 'premier-gunner-v7';
|
|
const SHELL = [
|
|
'/', '/index.html', '/login.html',
|
|
'/css/styles.css',
|
|
'/js/app.js', '/js/api.js', '/js/dashboard.js',
|
|
'/vendor/chart.umd.min.js',
|
|
'/manifest.webmanifest',
|
|
'/icons/logo.svg', '/icons/favicon.svg',
|
|
'/icons/icon-192.png', '/icons/icon-512.png',
|
|
];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
// Pre-cache the new shell, but do NOT skipWaiting automatically — we wait
|
|
// until the page tells us to (via the "Refresh" banner) so the update is
|
|
// controlled and the user is never interrupted mid-action.
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)));
|
|
});
|
|
|
|
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())
|
|
);
|
|
});
|
|
|
|
// The page posts this when the user taps "Refresh" on the update banner.
|
|
self.addEventListener('message', (e) => {
|
|
if (e.data && e.data.type === 'SKIP_WAITING') self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
const url = new URL(e.request.url);
|
|
if (e.request.method !== 'GET') return;
|
|
// Never cache the API — always go to network so data stays fresh and auth works.
|
|
if (url.pathname.startsWith('/api/')) return;
|
|
|
|
e.respondWith(
|
|
caches.match(e.request).then((cached) => {
|
|
const network = fetch(e.request).then((res) => {
|
|
if (res.ok && url.origin === location.origin) {
|
|
const copy = res.clone();
|
|
caches.open(CACHE).then((c) => c.put(e.request, copy));
|
|
}
|
|
return res;
|
|
}).catch(() => cached);
|
|
return cached || network;
|
|
})
|
|
);
|
|
});
|