fix: prevent double asset update

This commit is contained in:
2026-03-20 22:41:24 +07:00 Unverified
parent 4cabdb5691
commit 25b2525f98
2 changed files with 18 additions and 6 deletions
+1 -2
View File
@@ -18,7 +18,7 @@ export class AssetManager {
const [avatars, weapons, relics] = await Promise.all([
getEnkaAvatarStore(),
getEnkaWeaponStore(),
await getEnkaRelicStore(),
getEnkaRelicStore(),
]);
return [
...Object.values(avatars).flatMap((a) => [
@@ -58,7 +58,6 @@ export class AssetManager {
.then((d) => write(join("store", hash(name).toString(36)), d));
console.log("All missing assets fetched and stored");
this.purgeExtraAssets();
}
async purgeExtraAssets() {
+17 -4
View File
@@ -39,11 +39,24 @@ const font = file(fontFile);
const iconFont = file(iconFontFile);
const shade = file(shadeSvg);
queueMicrotask(async () => {
assets.getMissingAssets();
var purging = false;
setInterval(() => {
assets.getMissingAssets();
queueMicrotask(() => {
if (purging) return;
purging = true;
assets.getMissingAssets().finally(() => (purging = false));
setInterval(async () => {
if (purging) return;
purging = true;
try {
await assets.getMissingAssets();
await assets.purgeExtraAssets();
} catch (e) {
console.error(e);
} finally {
purging = false;
}
}, 86400000); // refresh assets every 24 hours
});