Make it a little faster, queue is in sqlite now, fix db bug and more
Some checks failed
Build and Deploy on Tag / 🔨 Build for everything else (push) Failing after 11s
Build and Deploy on Tag / 🔨 Build for PowerPC (push) Failing after 20s

This commit is contained in:
2026-06-25 15:35:39 -05:00
parent ede1f92981
commit c82957cc61
53 changed files with 661 additions and 888 deletions

View File

@@ -2,6 +2,13 @@ const assets = ["<@ASSETS@>"];
const staticCacheName = "tytd-static-<@BUILD_TIME@>";
async function ThrowOnBadGateway(req)
{
const resp = await fetch(req);
if(resp.status === 502) throw new Error("Bad Gateway");
return resp;
}
self.addEventListener('install',evt => {
evt.waitUntil(
caches.open(staticCacheName).then(cache =>{
@@ -19,24 +26,29 @@ self.addEventListener('activate',(evt)=>{
});
self.addEventListener('fetch', evt => {
const uri = new URL(evt.request.url);
evt.respondWith(
caches.match(evt.request).then(cacheRes=>{
return cacheRes || fetch(evt.request);
}).catch(()=>{
if(uri.pathname === '/queue-size')
console.warn('SW cacheRes:', cacheRes);
return cacheRes || ThrowOnBadGateway(evt.request);
}).catch((err)=>{
console.warn('SW Fallback:', err.message);
if(evt.request.headers.has('HX-Request'))
{
return new Response('<span hx-trigger="every 5000ms" hx-target="this" hx-push-url="false" hx-indicator="none" hx-get="./queue-size" hx-swap="outerHTML" class="badge">?</span>',{
headers: { 'Content-Type': 'text/html' }
});
return new Response("",{
status: 200,
headers: {
'HX-Redirect': "/offline.html"
}
});
}
if(uri.pathname === "/progress")
else
{
return caches.match("/offline-progress.html");
return caches.match('/offline.html');
}
return caches.match('/offline.html');
})
);
});
});