Always live-scan Studio 2 LoRAs on load and Refresh like Settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-18 12:59:06 -05:00
co-authored by Cursor
parent 7221b6a8cf
commit b194b3cefa
4 changed files with 36 additions and 27 deletions
+18 -14
View File
@@ -1,15 +1,19 @@
import { readFileSync,writeFileSync,renameSync } from 'node:fs';
import { join } from 'node:path';
import { cachedLoras } from '~/shared/studio2/lora-cache.mjs';
import { listStudioLoras } from '../../utils/loras';
import { studio2Root } from '../../utils/studio2/store';
import { studio2LoraCatalog } from '../../utils/studio2/lora-catalog';
import { readFileSync,writeFileSync,renameSync } from 'node:fs'
import { join } from 'node:path'
import { cachedLoras } from '~/shared/studio2/lora-cache.mjs'
import { listStudioLoras } from '../../utils/loras'
import { studio2Root } from '../../utils/studio2/store'
import { studio2LoraCatalog } from '../../utils/studio2/lora-catalog'
export default defineEventHandler(async event => {
const {owner}=assertLibraryOwner(event),path=join(studio2Root(),`loras-${owner}.cache`);
const listed=await cachedLoras({
read:()=>{try{return JSON.parse(readFileSync(path,'utf8'));}catch{return null;}},
write:value=>{writeFileSync(path+'.tmp',JSON.stringify(value));renameSync(path+'.tmp',path);},
live:()=>listStudioLoras({fresh:true}),fresh:getQuery(event).fresh==='1'
});
return {...listed,...studio2LoraCatalog(owner)};
});
const { owner } = assertLibraryOwner(event)
const path = join(studio2Root(), `loras-${owner}.cache`)
// Same live Comfy scan as Settings (/api/loras?fresh=1). Always fresh so CACHE_MS cannot freeze adds.
const listed = await cachedLoras({
read: () => { try { return JSON.parse(readFileSync(path, 'utf8')) } catch { return null } },
write: value => { writeFileSync(path + '.tmp', JSON.stringify(value)); renameSync(path + '.tmp', path) },
live: () => listStudioLoras({ fresh: true }),
fresh: true
})
return { ...listed, ...studio2LoraCatalog(owner) }
})