Add LoRA activation words and hide LoRAs that do not match the current engine.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { libraryOwnerKey, publicLibrary, setLoraTrigger } from '~/server/utils/library'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ key?: unknown; trigger?: unknown }>(event)
|
||||
const owner = libraryOwnerKey(event)
|
||||
await setLoraTrigger(owner, String(body?.key || ''), String(body?.trigger || ''))
|
||||
return publicLibrary(event)
|
||||
})
|
||||
+24
-4
@@ -9,7 +9,7 @@ import { extractFirstFrame, extractFrameAt, extractLastFrame, probeDuration, rem
|
||||
import { normalizePermanenceRefs, type PermanenceRef } from '~/utils/globalLocks'
|
||||
import { normalizeStillSettings, type StillGenerationSettings } from '~/utils/libraryGeneration'
|
||||
import { buildOutputBaseName, nextUniqueName, normalizeLoraAliases, sanitizeLoraAlias } from '~/utils/outputNames'
|
||||
import { loraIdentityKey, type LoraStackItem } from '~/utils/loras'
|
||||
import { loraIdentityKey, normalizeLoraTriggers, sanitizeLoraTrigger, type LoraStackItem } from '~/utils/loras'
|
||||
|
||||
const scryptAsync = promisify(scrypt)
|
||||
|
||||
@@ -131,6 +131,7 @@ interface Catalog {
|
||||
stills: LibraryStill[]
|
||||
drafts: RetryDraft[]
|
||||
loraAliases: Record<string, string>
|
||||
loraTriggers: Record<string, string>
|
||||
}
|
||||
|
||||
const writeChains = new Map<string, Promise<unknown>>()
|
||||
@@ -170,7 +171,8 @@ function emptyCatalog(): Catalog {
|
||||
clips: [],
|
||||
stills: [],
|
||||
drafts: [],
|
||||
loraAliases: {}
|
||||
loraAliases: {},
|
||||
loraTriggers: {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +232,8 @@ function normalizeCatalog(parsed: Partial<Catalog> & { passwordHash?: string | n
|
||||
clips: Array.isArray(parsed.clips) ? parsed.clips : [],
|
||||
stills: Array.isArray(parsed.stills) ? parsed.stills.map(normalizeStill) : [],
|
||||
drafts: Array.isArray(parsed.drafts) ? parsed.drafts : [],
|
||||
loraAliases: normalizeLoraAliases(parsed.loraAliases)
|
||||
loraAliases: normalizeLoraAliases(parsed.loraAliases),
|
||||
loraTriggers: normalizeLoraTriggers(parsed.loraTriggers)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,6 +386,22 @@ export function getLoraAliases(owner: string) {
|
||||
return { ...(readCatalog(owner).loraAliases || {}) }
|
||||
}
|
||||
|
||||
export function getLoraTriggers(owner: string) {
|
||||
return { ...(readCatalog(owner).loraTriggers || {}) }
|
||||
}
|
||||
|
||||
export async function setLoraTrigger(owner: string, identity: string, trigger: string) {
|
||||
const key = loraIdentityKey(identity) || String(identity || '').trim().toLowerCase()
|
||||
if (!key) throw createError({ statusCode: 400, statusMessage: 'A LoRA file is required' })
|
||||
const cleaned = sanitizeLoraTrigger(trigger)
|
||||
return mutate(owner, (catalog) => {
|
||||
if (!catalog.loraTriggers) catalog.loraTriggers = {}
|
||||
if (!cleaned) delete catalog.loraTriggers[key]
|
||||
else catalog.loraTriggers[key] = cleaned
|
||||
return { ...catalog.loraTriggers }
|
||||
})
|
||||
}
|
||||
|
||||
export async function setLoraAlias(owner: string, identity: string, alias: string) {
|
||||
const key = loraIdentityKey(identity) || String(identity || '').trim().toLowerCase()
|
||||
if (!key) throw createError({ statusCode: 400, statusMessage: 'A LoRA file is required' })
|
||||
@@ -486,7 +505,8 @@ export function publicLibrary(event: H3Event, opts?: { light?: boolean }) {
|
||||
.filter(still => unlockedIds.has(still.folderId) && !isPipelineStill(catalog, still, clipIds))
|
||||
.map(still => ({ ...still, role: stillRole(still) })),
|
||||
drafts: catalog.drafts,
|
||||
loraAliases: catalog.loraAliases || {}
|
||||
loraAliases: catalog.loraAliases || {},
|
||||
loraTriggers: catalog.loraTriggers || {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user