chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:58:53 +08:00
parent 74f15c282e
commit d861a9937b
38 changed files with 3570 additions and 2926 deletions

View File

@@ -0,0 +1,70 @@
const CACHE_NAME = 'mengyaping-shell-v1'
const SHELL_FILES = [
'/',
'/index.html',
'/manifest.webmanifest',
'/favicon.ico',
'/icons/icon-192.png',
'/icons/icon-512.png',
'/icons/icon-512-maskable.png',
]
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_FILES))
)
self.skipWaiting()
})
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) =>
Promise.all(
cacheNames
.filter((cacheName) => cacheName !== CACHE_NAME)
.map((cacheName) => caches.delete(cacheName))
)
)
)
self.clients.claim()
})
self.addEventListener('fetch', (event) => {
const { request } = event
if (request.method !== 'GET') {
return
}
const url = new URL(request.url)
// Only cache same-origin requests, leave API calls untouched.
if (url.origin !== self.location.origin) {
return
}
if (request.mode === 'navigate') {
event.respondWith(
fetch(request).catch(() => caches.match('/index.html'))
)
return
}
event.respondWith(
caches.match(request).then((cachedResponse) => {
if (cachedResponse) {
return cachedResponse
}
return fetch(request).then((networkResponse) => {
if (!networkResponse || networkResponse.status !== 200) {
return networkResponse
}
const responseClone = networkResponse.clone()
caches.open(CACHE_NAME).then((cache) => cache.put(request, responseClone))
return networkResponse
})
})
)
})