Translate UI to English and add PWA support
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
const CACHE_NAME = "llm-monitor-v1";
|
||||
const APP_SHELL = [
|
||||
"/",
|
||||
"/models-running",
|
||||
"/models-available",
|
||||
"/static/css/output.css",
|
||||
"/static/js/app.js",
|
||||
"/static/js/models-running.js",
|
||||
"/static/js/data-sync.worker.js",
|
||||
"/static/js/pwa-register.js",
|
||||
"/manifest.webmanifest",
|
||||
"/favicon.ico"
|
||||
];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(
|
||||
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
|
||||
)
|
||||
)
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
if (event.request.method !== "GET") {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestUrl = new URL(event.request.url);
|
||||
const isApiRequest = requestUrl.pathname.startsWith("/api/");
|
||||
|
||||
if (isApiRequest) {
|
||||
event.respondWith(
|
||||
fetch(event.request).catch(() =>
|
||||
new Response(JSON.stringify({ detail: "Offline" }), {
|
||||
status: 503,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
})
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((cached) => {
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
return fetch(event.request)
|
||||
.then((response) => {
|
||||
if (!response || response.status !== 200 || response.type !== "basic") {
|
||||
return response;
|
||||
}
|
||||
|
||||
const responseClone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, responseClone));
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match("/models-running"));
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user