6 Commits

Author SHA1 Message Date
3f771bf7b0 Merge pull request 'Fix when people order multiple times' (#26) from development into main
All checks were successful
Build Docker image / build (push) Successful in 2m54s
Build Docker image / deploy (push) Successful in 4s
Build Docker image / verify (push) Successful in 42s
Reviewed-on: #26
2025-09-03 08:35:00 +02:00
e78902d79f Merge pull request 'development' (#25) from development into main
All checks were successful
Build Docker image / build (push) Successful in 1m14s
Build Docker image / deploy (push) Successful in 3s
Build Docker image / verify (push) Successful in 28s
Reviewed-on: #25
2025-09-02 19:37:17 +02:00
Roman Krček
e52aea9dd3 Fixed private pages being cached
All checks were successful
Build Docker image / build (push) Successful in 1m22s
Build Docker image / deploy (push) Successful in 4s
Build Docker image / verify (push) Successful in 1m8s
2025-09-02 18:43:49 +02:00
cdc8b89916 Merge pull request 'Added loading indicator' (#24) from development into main
All checks were successful
Build Docker image / build (push) Successful in 3m19s
Build Docker image / deploy (push) Successful in 3s
Build Docker image / verify (push) Successful in 1m57s
Reviewed-on: #24
2025-09-02 18:26:28 +02:00
9dd79514f5 Merge branch 'main' into development 2025-09-02 18:21:55 +02:00
Roman Krček
cd37d8da0f Added loading indicator 2025-09-02 18:18:58 +02:00
2 changed files with 68 additions and 52 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "scan-wave", "name": "scan-wave",
"private": true, "private": true,
"version": "0.0.2", "version": "0.0.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",

View File

@@ -1,71 +1,87 @@
/// <reference lib="webworker" />
/// <reference types="@sveltejs/kit" /> /// <reference types="@sveltejs/kit" />
import { build, files, version } from '$service-worker'; import { build, files, version } from '$service-worker';
declare const self: ServiceWorkerGlobalScope; // Create a unique cache name for this deployment
const CACHE = `cache-${version}`; const CACHE = `cache-${version}`;
const ASSETS = [ const ASSETS = [
...build, ...build, // the app itself
...files ...files // everything in `static`
]; ];
self.addEventListener('install', (event: ExtendableEvent) => { self.addEventListener('install', (event) => {
const addFilesToCache = async () => { // Create a new cache and add all files to it
const cache = await caches.open(CACHE); async function addFilesToCache() {
await cache.addAll(ASSETS); const cache = await caches.open(CACHE);
}; await cache.addAll(ASSETS);
}
console.log("[SW] Installing new service worker"); event.waitUntil(addFilesToCache());
event.waitUntil(addFilesToCache());
self.skipWaiting();
}); });
self.addEventListener('activate', (event: ExtendableEvent) => { self.addEventListener('activate', (event) => {
const deleteOldCaches = async () => { // Remove previous cached data from disk
for (const key of await caches.keys()) { async function deleteOldCaches() {
if (key !== CACHE) await caches.delete(key); for (const key of await caches.keys()) {
console.log("[SW] Removing old service worker") if (key !== CACHE) await caches.delete(key);
} }
}; }
event.waitUntil(deleteOldCaches()); event.waitUntil(deleteOldCaches());
self.clients.claim();
}); });
self.addEventListener('fetch', (event: FetchEvent) => { self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') return; // ignore POST requests etc
if (event.request.method !== 'GET') return;
const url = new URL(event.request.url); async function respond() {
const url = new URL(event.request.url);
// Skip caching for auth routes
if (url.pathname.startsWith('/auth/')) {
return fetch(event.request);
}
// Never cache private routes const cache = await caches.open(CACHE);
if (url.pathname.startsWith('/private')) {
event.respondWith(fetch(event.request));
return;
}
const respond = async () => { // `build`/`files` can always be served from the cache
const cache = await caches.open(CACHE); if (ASSETS.includes(url.pathname)) {
const response = await cache.match(url.pathname);
if (ASSETS.includes(url.pathname)) { if (response) {
const cached = await cache.match(url.pathname); return response;
if (cached) return cached; }
} }
try { // for everything else, try the network first, but
const response = await fetch(event.request); // fall back to the cache if we're offline
if (response.status === 200 && build.length > 0 && url.pathname.startsWith(`/${build[0]}/`)) { try {
cache.put(event.request, response.clone()); const response = await fetch(event.request);
}
return response;
} catch {
const cached = await cache.match(event.request);
if (cached) return cached;
}
return new Response('Not found', { status: 404 }); // 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');
}
event.respondWith(respond()); // Do not cache private pages
}); if (response.status === 200 && !url.pathname.startsWith('/private')) {
cache.put(event.request, response.clone());
}
return response;
} catch (err) {
const response = await cache.match(event.request);
if (response) {
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());
});