Simplify Studio 2 sources and persist private previews and LoRA lists
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
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 { getLoraAliases, getLoraTriggers } from '../../utils/library';
|
||||
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,aliases:getLoraAliases(owner),triggers:getLoraTriggers(owner)};
|
||||
});
|
||||
Reference in New Issue
Block a user