Make it a little faster, queue is in sqlite now, fix db bug and more
This commit is contained in:
@@ -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');
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user