mirror of
https://github.com/paricafe/misskey.git
synced 2025-02-25 00:34:25 -06:00
restore sw.ts
This commit is contained in:
parent
682cbd9a5f
commit
98db77fa90
1 changed files with 38 additions and 81 deletions
|
@ -12,24 +12,7 @@ import { createEmptyNotification, createNotification } from '@/scripts/create-no
|
|||
import { swLang } from '@/scripts/lang.js';
|
||||
import * as swos from '@/scripts/operations.js';
|
||||
|
||||
const CACHE_NAMES = {
|
||||
assets: `assets-${_VERSION_}`,
|
||||
emoji: `emoji-${_VERSION_}`,
|
||||
twemoji: `twemoji-${_VERSION_}`,
|
||||
fluentEmoji: `fluent-emoji-${_VERSION_}`,
|
||||
vite: `vite-${_VERSION_}`,
|
||||
locale: swLang.cacheName,
|
||||
};
|
||||
|
||||
const CACHE_PATHS = {
|
||||
[CACHE_NAMES.assets]: '/assets',
|
||||
[CACHE_NAMES.emoji]: '/emoji',
|
||||
[CACHE_NAMES.twemoji]: '/twemoji',
|
||||
[CACHE_NAMES.fluentEmoji]: '/fluent-emoji',
|
||||
[CACHE_NAMES.vite]: '/vite',
|
||||
};
|
||||
|
||||
globalThis.addEventListener('install', (ev) => {
|
||||
globalThis.addEventListener('install', () => {
|
||||
// ev.waitUntil(globalThis.skipWaiting());
|
||||
});
|
||||
|
||||
|
@ -38,9 +21,7 @@ globalThis.addEventListener('activate', ev => {
|
|||
caches.keys()
|
||||
.then(cacheNames => Promise.all(
|
||||
cacheNames
|
||||
.filter((name) => {
|
||||
return !Object.values(CACHE_NAMES).includes(name);
|
||||
})
|
||||
.filter((v) => v !== swLang.cacheName)
|
||||
.map(name => caches.delete(name)),
|
||||
))
|
||||
.then(() => globalThis.clients.claim()),
|
||||
|
@ -59,30 +40,6 @@ async function offlineContentHTML() {
|
|||
}
|
||||
|
||||
globalThis.addEventListener('fetch', ev => {
|
||||
const url = new URL(ev.request.url);
|
||||
const matchedCache = Object.entries(CACHE_PATHS).find(([, path]) => url.pathname.startsWith(path));
|
||||
|
||||
if (matchedCache) {
|
||||
ev.respondWith(
|
||||
caches.open(matchedCache[0])
|
||||
.then(cache =>
|
||||
cache.match(ev.request)
|
||||
.then(response => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return fetch(ev.request)
|
||||
.then(response => {
|
||||
cache.put(ev.request, response.clone());
|
||||
return response;
|
||||
});
|
||||
})
|
||||
)
|
||||
.catch(() => fetch(ev.request))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let isHTMLRequest = false;
|
||||
if (ev.request.headers.get('sec-fetch-dest') === 'document') {
|
||||
isHTMLRequest = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue