fix: always load account center for authenticated users

This commit is contained in:
pavlov346346-source 2026-09-12 10:11:09 +03:00
parent bd7995d68c
commit ce1930ef5d

View File

@ -1,5 +1,5 @@
const CACHE='sun-catering-pwa-v80-20260912-account-center';
const VERSION='20260912-account-center';
const CACHE='sun-catering-pwa-v81-20260912-account-center-loader';
const VERSION='20260912-account-center-loader';
const CORE=[
'./','./index.html',
`./core/sun-safe.js?v=${VERSION}`,`./core/performance.js?v=${VERSION}`,`./core/account-center-v1780.js?v=${VERSION}`,`./core/login-signature-v1776.js?v=${VERSION}`,`./core/data-layer-v1773.js?v=${VERSION}`,`./core/server-automation-v1770.js?v=${VERSION}`,`./core/hotfix-v1763.js?v=${VERSION}`,`./core/ops-ux-v1762.js?v=${VERSION}`,`./core/ux-fixes-v1764.js?v=${VERSION}`,`./core/pdf-engine.js?v=${VERSION}`,`./core/classic-offer-pdf-v1767.js?v=${VERSION}`,`./core/developer-console-v1768.js?v=${VERSION}`,`./core/offer-workspace-v1769.js?v=${VERSION}`,`./legacy/bootstrap.js?v=${VERSION}`,`./app-runtime.js?v=${VERSION}`,
@ -34,11 +34,22 @@ function forceFresh(req){
url.searchParams.set('__caterium_release',VERSION);
return fetch(url.toString(),{cache:'no-store',credentials:'same-origin'}).then(res=>cachePut(req,res)).catch(()=>caches.match(req));
}
async function withAccountCenter(res){
if(!res)return res;
const type=String(res.headers.get('content-type')||'');
if(!type.includes('text/html'))return res;
const html=await res.text();
if(html.includes('core/account-center-v1780.js'))return new Response(html,{status:res.status,statusText:res.statusText,headers:res.headers});
const tag=`<script src="core/account-center-v1780.js?v=${VERSION}"></script>`;
const out=html.includes('</body>')?html.replace('</body>',`${tag}</body>`):html+tag;
const headers=new Headers(res.headers);headers.set('content-type','text/html; charset=utf-8');headers.set('cache-control','no-store, max-age=0');
return new Response(out,{status:res.status,statusText:res.statusText,headers});
}
self.addEventListener('fetch',event=>{
const req=event.request;if(req.method!=='GET')return;
const url=new URL(req.url);if(url.pathname.startsWith('/api/'))return;
if(req.mode==='navigate'){
event.respondWith(fetch(req,{cache:'no-store'}).then(res=>{const clone=res.clone();caches.open(CACHE).then(c=>c.put('./index.html',clone)).catch(()=>{});return res}).catch(()=>caches.match('./index.html')));return;
event.respondWith(fetch(req,{cache:'no-store'}).then(async res=>{const clone=res.clone();caches.open(CACHE).then(c=>c.put('./index.html',clone)).catch(()=>{});return withAccountCenter(res)}).catch(async()=>withAccountCenter(await caches.match('./index.html'))));return;
}
if(CRITICAL_FRESH.has(url.pathname)){
event.respondWith(forceFresh(req));return;
@ -46,4 +57,4 @@ self.addEventListener('fetch',event=>{
const freshAsset=/\.(?:js|css|webmanifest)$/i.test(url.pathname);
if(freshAsset){event.respondWith(networkFirst(req));return;}
event.respondWith(caches.match(req).then(cached=>cached||fetch(req,{cache:'no-store'}).then(res=>cachePut(req,res))));
});
});