Add manual image groups to the library

This commit is contained in:
Towsty
2026-09-07 20:16:01 -05:00
parent 174d40a7dc
commit eeff12cdab
5 changed files with 164 additions and 9 deletions
+38 -2
View File
@@ -105,6 +105,9 @@ export interface LibraryStill {
promptPre?: string
promptPost?: string
familyId?: string
manualGroupId?: string
manualGroupName?: string
manualGroupIndex?: number
parentStillId?: string
chainIndex?: number
settings?: StillGenerationSettings
@@ -258,6 +261,9 @@ function normalizeStill(still: LibraryStill): LibraryStill {
promptPre: still.promptPre,
promptPost: still.promptPost,
familyId: still.familyId,
manualGroupId: still.manualGroupId,
manualGroupName: still.manualGroupName,
manualGroupIndex: still.manualGroupIndex,
parentStillId: still.parentStillId,
chainIndex: still.chainIndex,
settings: normalizeStillSettings(still.settings)
@@ -413,10 +419,11 @@ export function clipsInSameFamily(catalog: Catalog, clip: LibraryClip) {
export function stillsInSameFamily(catalog: Catalog, still: LibraryStill) {
const folderStills = catalog.stills.filter(item => item.folderId === still.folderId && stillRole(item) === 'output')
if (still.manualGroupId) return folderStills.filter(item => item.manualGroupId === still.manualGroupId)
const ids = new Set<string>([still.id])
if (still.familyId) {
for (const item of folderStills) {
if (item.familyId === still.familyId) ids.add(item.id)
if (!item.manualGroupId && item.familyId === still.familyId) ids.add(item.id)
}
}
return folderStills.filter(item => ids.has(item.id))
@@ -1580,7 +1587,7 @@ export function moveStillFamily(owner: string, id: string, folderId: string) {
const familyId = family.find(item => item.familyId)?.familyId || still.familyId || crypto.randomUUID()
for (const item of family) {
item.folderId = folder.id
item.familyId = familyId
if (!still.manualGroupId) item.familyId = familyId
}
return family
})
@@ -1617,6 +1624,10 @@ export function renameStillFamily(owner: string, id: string, name: string) {
const family = [...stillsInSameFamily(catalog, still)].sort((a, b) => (a.chainIndex || 0) - (b.chainIndex || 0) || a.createdAt - b.createdAt)
const base = familyBaseName(trimmed) || trimmed
const familyId = family.find(item => item.familyId)?.familyId || still.familyId || crypto.randomUUID()
if (still.manualGroupId) {
for (const item of family) item.manualGroupName = trimmed
return family
}
family.forEach((item, index) => {
item.familyId = familyId
item.name = stillChainName(base, index)
@@ -2153,3 +2164,28 @@ export async function importMissingComfyAudio(owner: string, folderId?: string)
}
return imported
}
// Grouping only changes library organization; generation ancestry remains intact.
export function groupLibraryStills(owner: string, ids: string[], ungroup = false) {
return mutate(owner, (catalog) => {
const selected = ids.map(id => catalog.stills.find(item => item.id === id))
if (selected.some(item => !item || stillRole(item) !== 'output')) throw createError({ statusCode: 400, statusMessage: 'Choose generated images' })
const images = selected as LibraryStill[]
if (new Set(images.map(item => item.folderId)).size !== 1) throw createError({ statusCode: 400, statusMessage: 'Move the images into the same folder first' })
const members = [...new Map(images.flatMap(item => stillsInSameFamily(catalog, item)).map(item => [item.id, item])).values()]
if (!ungroup && members.length < 2) throw createError({ statusCode: 400, statusMessage: 'Select at least two images' })
const groupId = crypto.randomUUID()
const name = images.find(item => item.manualGroupName)?.manualGroupName || 'Image group'
members.forEach((item, index) => {
if (ungroup) {
delete item.manualGroupId
delete item.manualGroupName
delete item.manualGroupIndex
} else {
item.manualGroupId = groupId
item.manualGroupName = name
item.manualGroupIndex = index
}
})
})
}