fix: commit sw.js v3 source + invite_codes remark migration (both were missed by earlier pathspecs)
This commit is contained in:
+25
-17
@@ -1,9 +1,9 @@
|
|||||||
// PWA Service Worker v2
|
// PWA Service Worker v3
|
||||||
// - 页面导航:网络优先(构建更新后强制拿到新 index.html),离线才回落缓存
|
// - /api /auth /admin /sync 一律直连,绝不缓存(修复切换账号后 /auth/me 命中旧缓存的问题)
|
||||||
// - 静态资源:缓存优先
|
// - 仅指纹化静态资源(/assets/、/icons/)缓存优先
|
||||||
// - /api:直连不缓存
|
// - 页面导航网络优先,离线回落缓存的 index.html
|
||||||
const CACHE = 'fp-static-v2';
|
const CACHE = 'fp-static-v3';
|
||||||
const CORE = ['/', '/manifest.webmanifest', '/icons/pwa-192.png', '/icons/pwa-512.png'];
|
const CORE = ['/manifest.webmanifest', '/icons/pwa-192.png', '/icons/pwa-512.png'];
|
||||||
|
|
||||||
self.addEventListener('install', (e) => {
|
self.addEventListener('install', (e) => {
|
||||||
self.skipWaiting();
|
self.skipWaiting();
|
||||||
@@ -20,8 +20,25 @@ self.addEventListener('activate', (e) => {
|
|||||||
|
|
||||||
self.addEventListener('fetch', (e) => {
|
self.addEventListener('fetch', (e) => {
|
||||||
const url = new URL(e.request.url);
|
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') {
|
if (e.request.mode === 'navigate') {
|
||||||
e.respondWith(
|
e.respondWith(
|
||||||
fetch(e.request).then((res) => {
|
fetch(e.request).then((res) => {
|
||||||
@@ -32,14 +49,5 @@ self.addEventListener('fetch', (e) => {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 其余(manifest 等):网络直连
|
||||||
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;
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ CREATE TABLE IF NOT EXISTS attachments (
|
|||||||
used_at TEXT,
|
used_at TEXT,
|
||||||
valid INTEGER NOT NULL DEFAULT 1
|
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;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user