📼 Updates reponse cache to use indexedDB

This commit is contained in:
Rune Harlyk
2023-08-01 03:08:42 +02:00
parent 8f35e534cb
commit cbf5ddec1c
3 changed files with 118 additions and 7 deletions
+12 -2
View File
@@ -8,6 +8,7 @@
import Health from './routes/SystemHealth.svelte';
import location from './lib/location';
import Sidebar from './components/Sidebar.svelte';
import FileCache from './lib/cache';
export let url = window.location.pathname;
onMount(() => {
@@ -18,9 +19,18 @@
const registerFetchIntercept = () => {
const { fetch: originalFetch } = window;
window.fetch = async (...args) => {
const cache = await caches.open("files")
const [resource, config] = args;
return await cache.match(resource) ?? originalFetch(resource, config)
await FileCache.openDatabase();
let file;
try {
file = await FileCache.getFile(resource.url);
} catch (error) {
console.log(error);
}
return file
? new Response(file)
: originalFetch(resource, config)
};
}
</script>