mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-03 11:43:39 -07:00
server: snapshot
This commit is contained in:
@@ -1563,7 +1563,7 @@
|
||||
<link rel="modulepreload" href="/scripts/entry.7b7383d1.js">
|
||||
<link rel="modulepreload" href="/scripts/lazy.1ae52534.js">
|
||||
<link rel="modulepreload" href="/scripts/main.22a5bd79.js">
|
||||
<link rel="modulepreload" href="/scripts/modules/brk-client/index.c18ba682.js">
|
||||
<link rel="modulepreload" href="/scripts/modules/brk-client/index.74c13abc.js">
|
||||
<link rel="modulepreload" href="/scripts/modules/brk-client/tests/basic.b92ff866.js">
|
||||
<link rel="modulepreload" href="/scripts/modules/brk-client/tests/tree.ba9474f7.js">
|
||||
<link rel="modulepreload" href="/scripts/modules/lean-qr/2.6.1/index.09195c13.mjs">
|
||||
@@ -1634,7 +1634,7 @@
|
||||
"/scripts/entry.js": "/scripts/entry.7b7383d1.js",
|
||||
"/scripts/lazy.js": "/scripts/lazy.1ae52534.js",
|
||||
"/scripts/main.js": "/scripts/main.22a5bd79.js",
|
||||
"/scripts/modules/brk-client/index.js": "/scripts/modules/brk-client/index.c18ba682.js",
|
||||
"/scripts/modules/brk-client/index.js": "/scripts/modules/brk-client/index.74c13abc.js",
|
||||
"/scripts/modules/brk-client/tests/basic.js": "/scripts/modules/brk-client/tests/basic.b92ff866.js",
|
||||
"/scripts/modules/brk-client/tests/tree.js": "/scripts/modules/brk-client/tests/tree.ba9474f7.js",
|
||||
"/scripts/modules/lean-qr/2.6.1/index.mjs": "/scripts/modules/lean-qr/2.6.1/index.09195c13.mjs",
|
||||
|
||||
@@ -3,8 +3,14 @@ const ROOT = "/";
|
||||
const API = "/api";
|
||||
|
||||
const BYPASS = new Set([
|
||||
"/changelog", "/crate", "/discord", "/github", "/health",
|
||||
"/install", "/mcp", "/nostr", "/service", "/status", "/version"
|
||||
"/changelog",
|
||||
"/crate",
|
||||
"/discord",
|
||||
"/github",
|
||||
"/install",
|
||||
"/nostr",
|
||||
"/service",
|
||||
"/status",
|
||||
]);
|
||||
|
||||
// Match hashed filenames: name.abc12345.js/mjs/css
|
||||
@@ -13,16 +19,18 @@ const HASHED_RE = /\.[0-9a-f]{8}\.(js|mjs|css)$/;
|
||||
/** @type {ServiceWorkerGlobalScope} */
|
||||
const sw = /** @type {any} */ (self);
|
||||
|
||||
const offline = () => new Response("Offline", {
|
||||
status: 503,
|
||||
headers: { "Content-Type": "text/plain" }
|
||||
});
|
||||
const offline = () =>
|
||||
new Response("Offline", {
|
||||
status: 503,
|
||||
headers: { "Content-Type": "text/plain" },
|
||||
});
|
||||
|
||||
sw.addEventListener("install", (e) => {
|
||||
e.waitUntil(
|
||||
caches.open(CACHE)
|
||||
caches
|
||||
.open(CACHE)
|
||||
.then((c) => c.addAll([ROOT]))
|
||||
.then(() => sw.skipWaiting())
|
||||
.then(() => sw.skipWaiting()),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,10 +38,14 @@ sw.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
Promise.all([
|
||||
sw.clients.claim(),
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
||||
),
|
||||
])
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) =>
|
||||
Promise.all(
|
||||
keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -57,7 +69,7 @@ sw.addEventListener("fetch", (event) => {
|
||||
if (res.ok) caches.open(CACHE).then((c) => c.put(ROOT, res.clone()));
|
||||
return res;
|
||||
})
|
||||
.catch(() => caches.match(ROOT).then((c) => c || offline()))
|
||||
.catch(() => caches.match(ROOT).then((c) => c || offline())),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -65,15 +77,18 @@ sw.addEventListener("fetch", (event) => {
|
||||
// Hashed assets: cache-first (immutable)
|
||||
if (HASHED_RE.test(path)) {
|
||||
event.respondWith(
|
||||
caches.match(req)
|
||||
.then((cached) =>
|
||||
cached ||
|
||||
fetch(req).then((res) => {
|
||||
if (res.ok) caches.open(CACHE).then((c) => c.put(req, res.clone()));
|
||||
return res;
|
||||
})
|
||||
caches
|
||||
.match(req)
|
||||
.then(
|
||||
(cached) =>
|
||||
cached ||
|
||||
fetch(req).then((res) => {
|
||||
if (res.ok)
|
||||
caches.open(CACHE).then((c) => c.put(req, res.clone()));
|
||||
return res;
|
||||
}),
|
||||
)
|
||||
.catch(() => offline())
|
||||
.catch(() => offline()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -88,9 +103,15 @@ sw.addEventListener("fetch", (event) => {
|
||||
return res;
|
||||
})
|
||||
.catch(() =>
|
||||
caches.match(req).then((cached) =>
|
||||
cached || (isStatic ? offline() : caches.match(ROOT).then((c) => c || offline()))
|
||||
)
|
||||
)
|
||||
caches
|
||||
.match(req)
|
||||
.then(
|
||||
(cached) =>
|
||||
cached ||
|
||||
(isStatic
|
||||
? offline()
|
||||
: caches.match(ROOT).then((c) => c || offline())),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user