Files
aigen/shared/studio2/lora-cache.mjs
T

15 lines
589 B
JavaScript

export async function cachedLoras({read,write,live,fresh=false}) {
const cached=read() || {image:[],video:[]};
if (!fresh && (cached.image?.length || cached.video?.length)) return cached;
try {
const listed=await live();
const image=Array.isArray(listed?.image)?listed.image:[];
const video=Array.isArray(listed?.video)?listed.video:[];
// Comfy asleep / empty: keep disk. Otherwise replace — never merge stale names that freeze adds.
if (!image.length && !video.length) return cached;
const next={image,video};
write(next);
return next;
} catch { return cached; }
}