fix: commit sw.js v3 source + invite_codes remark migration (both were missed by earlier pathspecs)

This commit is contained in:
root
2026-10-16 20:03:22 +08:00
parent cc468027ca
commit 4e342ee77c
2 changed files with 27 additions and 17 deletions
+25 -17
View File
@@ -1,9 +1,9 @@
// PWA Service Worker v2
// - 页面导航:网络优先(构建更新后强制拿到新 index.html),离线才回落缓存
// - 静态资源:缓存优先
// - /api:直连不缓存
const CACHE = 'fp-static-v2';
const CORE = ['/', '/manifest.webmanifest', '/icons/pwa-192.png', '/icons/pwa-512.png'];
// PWA Service Worker v3
// - /api /auth /admin /sync 一律直连,绝不缓存(修复切换账号后 /auth/me 命中旧缓存的问题)
// - 仅指纹化静态资源(/assets/、/icons/)缓存优先
// - 页面导航网络优先,离线回落缓存的 index.html
const CACHE = 'fp-static-v3';
const CORE = ['/manifest.webmanifest', '/icons/pwa-192.png', '/icons/pwa-512.png'];
self.addEventListener('install', (e) => {
self.skipWaiting();
@@ -20,8 +20,25 @@ self.addEventListener('activate', (e) => {
self.addEventListener('fetch', (e) => {
const url = new URL(e.request.url);
if (e.request.method !== 'GET' || url.pathname.startsWith('/api')) return;
if (e.request.method !== 'GET') return;
// 后端接口直连(含 /api /auth /admin /sync),绝不缓存
if (/^\/(api|auth|admin|sync)(\/|$)/.test(url.pathname)) return;
// 指纹化静态资源:缓存优先(内容不可变)
if (url.pathname.startsWith('/assets/') || url.pathname.startsWith('/icons/')) {
e.respondWith(
caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => {
if (res.ok && url.origin === location.origin) {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(e.request, copy));
}
return res;
}))
);
return;
}
// 页面导航:网络优先,离线回落
if (e.request.mode === 'navigate') {
e.respondWith(
fetch(e.request).then((res) => {
@@ -32,14 +49,5 @@ self.addEventListener('fetch', (e) => {
);
return;
}
e.respondWith(
caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => {
if (res.ok && url.origin === location.origin) {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(e.request, copy));
}
return res;
}))
);
// 其余(manifest 等):网络直连
});
+2
View File
@@ -93,6 +93,8 @@ CREATE TABLE IF NOT EXISTS attachments (
used_at TEXT,
valid INTEGER NOT NULL DEFAULT 1
);`);
const hasRemark = db.prepare("SELECT COUNT(*) AS c FROM pragma_table_info('invite_codes') WHERE name='remark'").get().c;
if (Number(hasRemark) === 0) db.exec("ALTER TABLE invite_codes ADD COLUMN remark TEXT;");
return db;
}