The next-generation file converter. Open source, fully local* and free forever.
fix: fix offline cache?
JovannMCcda77f4e1235
diff --git a/bun.lock b/bun.lockindex c8a3696..e9566ac 100644--- a/bun.lock+++ b/bun.lock@@ -142,6 +142,8 @@"@jridgewell/set-array": ["@jridgewell/[email protected]", "", {}, "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A=="],+ "@jridgewell/source-map": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25" } }, "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ=="],+"@jridgewell/sourcemap-codec": ["@jridgewell/[email protected]", "", {}, "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ=="],"@jridgewell/trace-mapping": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ=="],@@ -300,6 +302,8 @@"browserslist": ["[email protected]", "", { "dependencies": { "caniuse-lite": "^1.0.30001688", "electron-to-chromium": "^1.5.73", "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.1" }, "bin": { "browserslist": "cli.js" } }, "sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A=="],+ "buffer-from": ["[email protected]", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="],+"callsites": ["[email protected]", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],"camelcase-css": ["[email protected]", "", {}, "sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA=="],@@ -634,8 +638,12 @@"sirv": ["[email protected]", "", { "dependencies": { "@polka/url": "^1.0.0-next.24", "mrmime": "^2.0.0", "totalist": "^3.0.0" } }, "sha512-BPwJGUeDaDCHihkORDchNyyTvWFhcusy1XMmhEVTQTwGeybFbp8YEmB+njbPnth1FibULBSBVwCQni25XlCUDg=="],+ "source-map": ["[email protected]", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],+"source-map-js": ["[email protected]", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],+ "source-map-support": ["[email protected]", "", { "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w=="],+"string-width": ["[email protected]", "", { "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", "strip-ansi": "^7.0.1" } }, "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA=="],"string-width-cjs": ["[email protected]", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],@@ -662,6 +670,8 @@"tailwindcss": ["[email protected]", "", { "dependencies": { "@alloc/quick-lru": "^5.2.0", "arg": "^5.0.2", "chokidar": "^3.6.0", "didyoumean": "^1.2.2", "dlv": "^1.1.3", "fast-glob": "^3.3.2", "glob-parent": "^6.0.2", "is-glob": "^4.0.3", "jiti": "^1.21.6", "lilconfig": "^3.1.3", "micromatch": "^4.0.8", "normalize-path": "^3.0.0", "object-hash": "^3.0.0", "picocolors": "^1.1.1", "postcss": "^8.4.47", "postcss-import": "^15.1.0", "postcss-js": "^4.0.1", "postcss-load-config": "^4.0.2", "postcss-nested": "^6.2.0", "postcss-selector-parser": "^6.1.2", "resolve": "^1.22.8", "sucrase": "^3.35.0" }, "bin": { "tailwind": "lib/cli.js", "tailwindcss": "lib/cli.js" } }, "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og=="],+ "terser": ["[email protected]", "", { "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, "bin": { "terser": "bin/terser" } }, "sha512-w8CXxxbFA5zfNsR/i8HZq5bvn18AK0O9jj7hyo1YqkovLxEFa0uP0LCVGZRqiRaKRFxXhELBp8SteeAjEnfeJg=="],+"thenify": ["[email protected]", "", { "dependencies": { "any-promise": "^1.0.0" } }, "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw=="],"thenify-all": ["[email protected]", "", { "dependencies": { "thenify": ">= 3.1.0 < 4" } }, "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA=="],@@ -752,6 +762,8 @@"tailwindcss/postcss-load-config": ["[email protected]", "", { "dependencies": { "lilconfig": "^3.0.0", "yaml": "^2.3.4" }, "peerDependencies": { "postcss": ">=8.0.9", "ts-node": ">=9.0.0" }, "optionalPeers": ["postcss", "ts-node"] }, "sha512-bSVhyJGL00wMVoPUzAVAnbEoWyqRxkjv64tUl427SKnPrENtq6hJwUojroMz2VB+Q1edmi4IfrAPpami5VVgMQ=="],+ "terser/commander": ["[email protected]", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="],+"vite-plugin-static-copy/chokidar": ["[email protected]", "", { "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw=="],"wrap-ansi/ansi-styles": ["[email protected]", "", {}, "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug=="],diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelteindex a49ccf8..5bb8b84 100644--- a/src/routes/+layout.svelte+++ b/src/routes/+layout.svelte@@ -18,7 +18,6 @@dropping,} from "$lib/store/index.svelte";import "../app.scss";- import { log, error } from "$lib/logger";let { children } = $props();@@ -53,23 +52,6 @@);Settings.instance.load();-- if ("serviceWorker" in navigator) {- navigator.serviceWorker- .register("/service-worker.js")- .then((registration) => {- log(- ["PWA"],- `Service Worker registration successful with scope: ${registration.scope}`,- );- })- .catch((err) => {- error(- ["PWA"],- `Service Worker registration failed: ${err}`,- );- });- }});</script>diff --git a/src/service-worker.js b/src/service-worker.jsnew file mode 100644index 0000000..c731472--- /dev/null+++ b/src/service-worker.js@@ -0,0 +1,84 @@+/// <reference types="@sveltejs/kit" />+import { build, files, version } from '$service-worker';++// Create a unique cache name for this deployment+const CACHE = `cache-${version}`;++const ASSETS = [+ ...build, // the app itself+ ...files, // everything in `static`+];++self.addEventListener('install', (event) => {+ // Create a new cache and add all files to it+ async function addFilesToCache() {+ const cache = await caches.open(CACHE);+ await cache.addAll(ASSETS);+ }++ console.log('installing service worker for version', version);+ console.log('caching assets', ASSETS);++ event.waitUntil(addFilesToCache());+});++self.addEventListener('activate', (event) => {+ // Remove previous cached data from disk+ async function deleteOldCaches() {+ for (const key of await caches.keys()) {+ if (key !== CACHE) await caches.delete(key);+ }+ }++ event.waitUntil(deleteOldCaches());+});++self.addEventListener('fetch', (event) => {+ // ignore POST requests etc+ if (event.request.method !== 'GET') return;++ async function respond() {+ const url = new URL(event.request.url);+ const cache = await caches.open(CACHE);++ // `build`/`files` can always be served from the cache+ if (ASSETS.includes(url.pathname)) {+ const response = await cache.match(url.pathname);++ if (response) {+ return response;+ }+ }++ // for everything else, try the network first, but+ // fall back to the cache if we're offline+ try {+ const response = await fetch(event.request);++ // if we're offline, fetch can return a value that is not a Response+ // instead of throwing - and we can't pass this non-Response to respondWith+ if (!(response instanceof Response)) {+ throw new Error('invalid response from fetch');+ }++ if (response.status === 200) {+ cache.put(event.request, response.clone());+ }++ return response;+ } catch (err) {+ const response = await cache.match(event.request);++ if (response) {+ console.log(`Returning from Cache`, event.request.url);+ return response;+ }++ // if there's no cache, then just error out+ // as there is nothing we can do to respond to this request+ throw err;+ }+ }++ event.respondWith(respond());+});diff --git a/static/service-worker.js b/static/service-worker.jsdeleted file mode 100644index 4c80564..0000000--- a/static/service-worker.js+++ /dev/null@@ -1,19 +0,0 @@-self.addEventListener('install', (event) => {- event.waitUntil(- caches.open('vert-cache').then((cache) => {- return cache.addAll([- '/',- '/manifest.json',- '/lettermark.jpg',- ]);- })- );-});--self.addEventListener('fetch', (event) => {- event.respondWith(- caches.match(event.request).then((response) => {- return response || fetch(event.request);- })- );-});\ No newline at end of filediff --git a/vite.config.ts b/vite.config.tsindex ff6c6d7..07f3d05 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -9,7 +9,7 @@ export default defineConfig({{name: "vips-request-middleware",configureServer(server) {- server.middlewares.use((req, res, next) => {+ server.middlewares.use((_req, res, next) => {res.setHeader("Cross-Origin-Embedder-Policy","require-corp",