fix: 图片预览错误返回可读 503 + feat: PWA 支持(manifest/sw/图标)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||
<rect width="512" height="512" rx="96" fill="#0f0f11"/>
|
||||
<text x="256" y="330" font-family="system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif" font-size="220" font-weight="700" text-anchor="middle" fill="#00d9a3">BT</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 315 B |
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "BT 种子预览台",
|
||||
"short_name": "BT 预览台",
|
||||
"description": "搜索 / 解析 / 预览 BT 种子内容,并投递到本机下载工具",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait-primary",
|
||||
"background_color": "#0f0f11",
|
||||
"theme_color": "#0f0f11",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
const CACHE_NAME = 'bt-preview-v1'
|
||||
const SHELL = ['/', '/gate', '/settings', '/manifest.json', '/icon.svg']
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL)).then(() => self.skipWaiting())
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(self.clients.claim())
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event
|
||||
const url = new URL(request.url)
|
||||
|
||||
// API、图片预览、下载等动态请求走网络,不做缓存
|
||||
if (url.pathname.startsWith('/api/')) return
|
||||
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => {
|
||||
if (cached) return cached
|
||||
return fetch(request).then((res) => {
|
||||
if (request.method === 'GET' && res.status === 200 && res.type === 'basic') {
|
||||
const clone = res.clone()
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone)).catch(() => {})
|
||||
}
|
||||
return res
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user