|
|
|
|
@ -35,30 +35,33 @@ self.addEventListener("install", event => {
|
|
|
|
|
event.waitUntil(initCache())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function handleFetch(request) {
|
|
|
|
|
if (request.url.includes('/-/frame')) {
|
|
|
|
|
const url = new URL(request.url)
|
|
|
|
|
if (url.pathname === '/-/frame') {
|
|
|
|
|
const html = url.searchParams.get('html')
|
|
|
|
|
const csp = url.searchParams.get('csp')
|
|
|
|
|
return new Response(html, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'text/html; charset=utf-8',
|
|
|
|
|
'Content-Security-Policy': csp,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const resp = await caches.match(request)
|
|
|
|
|
if (resp) {
|
|
|
|
|
return resp
|
|
|
|
|
async function handleFetch(url, request) {
|
|
|
|
|
if (url.pathname === '/-/frame') {
|
|
|
|
|
const html = url.searchParams.get('html')
|
|
|
|
|
const csp = url.searchParams.get('csp')
|
|
|
|
|
return new Response(html, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'text/html; charset=utf-8',
|
|
|
|
|
'Content-Security-Policy': csp,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
return fetch(request)
|
|
|
|
|
const resp = await caches.match(request)
|
|
|
|
|
if (resp) {
|
|
|
|
|
return resp
|
|
|
|
|
} else {
|
|
|
|
|
return fetch(request)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.addEventListener('fetch', event => {
|
|
|
|
|
event.respondWith(handleFetch(event.request))
|
|
|
|
|
const url = new URL(event.request.url)
|
|
|
|
|
if (url.pathname.startsWith('/macchiato/api/')) {
|
|
|
|
|
return false
|
|
|
|
|
} else {
|
|
|
|
|
event.respondWith(handleFetch(url, event.request))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', event => {
|
|
|
|
|
|