fix: resource updates

This commit is contained in:
cha0s 2024-09-28 10:22:16 -05:00
parent da51111106
commit 0588dbf6c2
2 changed files with 5 additions and 13 deletions

View File

@ -50,18 +50,6 @@ export async function fetchResources(paths, {signal} = {}) {
return parseResources(paths, await response.arrayBuffer());
}
export class Cache {
async get() {
const {get} = await import('idb-keyval');
const resources = await get('$$silphius_resources');
return resources || {};
}
async set(manifest) {
const {set} = await import('idb-keyval');
return set('$$silphius_resources', manifest);
}
}
export async function get() {
const {get} = await import('idb-keyval');
const resources = await get('$$silphius_resources');

View File

@ -52,13 +52,17 @@ export async function loadManifest() {
watcher.on('add', async (path) => {
const asset = await computeAsset(path);
manifest[asset.path] = asset.hash.toString('hex');
resources[asset.path] = {asset: asset.asset.buffer, hash: asset.hash.buffer};
});
watcher.on('change', async (path) => {
const asset = await computeAsset(path);
manifest[asset.path] = asset.hash.toString('hex');
resources[asset.path] = {asset: asset.asset.buffer, hash: asset.hash.buffer};
});
watcher.on('unlink', async (path) => {
delete manifest[path.slice(import.meta.dirname.length - 1)];
const assetPath = path.slice(RESOURCES_PATH_REAL.length + 1);
delete resources[assetPath];
delete manifest[assetPath];
});
}
return manifest;