Spike 50 parts board: photos, offline mode, mobile viewer, login page
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
BIN
public/icon-192.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
public/icon-512.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
public/img/chassis.webp
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
public/img/electrics.webp
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
public/img/exhaust-radiator-tank-airfilter.webp
Normal file
|
After Width: | Height: | Size: 142 KiB |
BIN
public/img/motord.webp
Normal file
|
After Width: | Height: | Size: 171 KiB |
BIN
public/img/plastics.webp
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
public/img/suspension.webp
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
public/img/wheels.webp
Normal file
|
After Width: | Height: | Size: 132 KiB |
705
public/index.html
Normal file
1
public/manifest.webmanifest
Normal file
@@ -0,0 +1 @@
|
||||
{"name":"Spike 50 Parts Board","short_name":"Spike 50","start_url":"/","scope":"/","display":"standalone","background_color":"#12171d","theme_color":"#1d5fc4","icons":[{"src":"icon-192.png","sizes":"192x192","type":"image/png","purpose":"any maskable"},{"src":"icon-512.png","sizes":"512x512","type":"image/png","purpose":"any maskable"}]}
|
||||
33
public/sw.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// Offline support: app shell + photos cached on the device. Data changes are queued by the page itself.
|
||||
const V = "spike-v1";
|
||||
const SHELL = ["/", "manifest.webmanifest", "icon-192.png", "icon-512.png",
|
||||
"img/chassis.webp", "img/suspension.webp", "img/wheels.webp", "img/plastics.webp", "img/electrics.webp",
|
||||
"img/exhaust-radiator-tank-airfilter.webp", "img/motord.webp"];
|
||||
const okToCache = (r) => r && r.ok && !r.redirected && r.type === "basic";
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(caches.open(V).then((c) => Promise.all(SHELL.map((u) => fetch(u, { credentials: "same-origin" }).then((r) => okToCache(r) && c.put(u, r)).catch(() => {})))).then(() => self.skipWaiting()));
|
||||
});
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(caches.keys().then((ks) => Promise.all(ks.filter((k) => k !== V).map((k) => caches.delete(k)))).then(() => self.clients.claim()));
|
||||
});
|
||||
self.addEventListener("fetch", (e) => {
|
||||
const req = e.request, url = new URL(req.url);
|
||||
if (req.method !== "GET" || url.origin !== location.origin) return;
|
||||
if (url.pathname.startsWith("/api/") || url.pathname === "/login" || url.pathname === "/logout") return;
|
||||
if (url.pathname.startsWith("/uploads/photo-") || url.pathname.startsWith("/img/")) {
|
||||
e.respondWith(caches.match(req).then((hit) => hit || fetch(req).then((r) => { if (okToCache(r)) { const c = r.clone(); caches.open(V).then((ch) => ch.put(req, c)); } return r; })));
|
||||
return;
|
||||
}
|
||||
// everything else (page, drawings, manifest): network first, fall back to the saved copy
|
||||
e.respondWith(new Promise((resolve) => {
|
||||
const key = req.mode === "navigate" ? "/" : req;
|
||||
const fallback = () => caches.match(key, { ignoreSearch: url.pathname.startsWith("/uploads/") ? false : true }).then((hit) => resolve(hit || Response.error()));
|
||||
const timer = setTimeout(() => caches.match(key, { ignoreSearch: !url.pathname.startsWith("/uploads/") }).then((hit) => hit && resolve(hit)), 4000);
|
||||
fetch(req).then((r) => {
|
||||
clearTimeout(timer);
|
||||
if (okToCache(r)) { const c = r.clone(); caches.open(V).then((ch) => ch.put(key, c)); }
|
||||
resolve(r);
|
||||
}).catch(() => { clearTimeout(timer); fallback(); });
|
||||
}));
|
||||
});
|
||||