Pause the queue after the current clip for real, and carry global locks plus labeled permanence stills through generate and shot prompts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { addStudioJob, kickStudioQueue, listStudioJobs } from '~/server/utils/studioQueue'
|
||||
import { defaultVideoSteps, isLtxWorkflow, isTextToVideo, parseVideoWorkflow } from '~/utils/videoModels'
|
||||
import { normalizePermanenceRefs, resolveGlobalLocks, type PermanenceRef } from '~/utils/globalLocks'
|
||||
|
||||
function parseDuration(raw: unknown) {
|
||||
const seconds = Number(raw)
|
||||
@@ -12,14 +13,15 @@ function parseExtendDuration(raw: unknown) {
|
||||
}
|
||||
|
||||
function parseExtensions(raw: string | undefined) {
|
||||
if (!raw) return [] as { prompt: string; duration: number }[]
|
||||
if (!raw) return [] as { prompt: string; duration: number; permanenceRefs?: PermanenceRef[] }[]
|
||||
try {
|
||||
const parsed = JSON.parse(raw)
|
||||
if (!Array.isArray(parsed)) return []
|
||||
return parsed
|
||||
.map((item: { prompt?: unknown; duration?: unknown }) => ({
|
||||
.map((item: { prompt?: unknown; duration?: unknown; permanenceRefs?: unknown }) => ({
|
||||
prompt: String(item?.prompt || '').trim(),
|
||||
duration: parseExtendDuration(item?.duration)
|
||||
duration: parseExtendDuration(item?.duration),
|
||||
permanenceRefs: normalizePermanenceRefs(item?.permanenceRefs)
|
||||
}))
|
||||
.filter(item => item.prompt)
|
||||
} catch {
|
||||
@@ -27,6 +29,26 @@ function parseExtensions(raw: string | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseFamilyPermanenceRefs(raw: string | undefined) {
|
||||
if (!raw) return [] as PermanenceRef[]
|
||||
try {
|
||||
return normalizePermanenceRefs(JSON.parse(raw))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function parseShotPermanenceRefs(raw: string | undefined, shotCount: number) {
|
||||
if (!raw) return Array.from({ length: shotCount }, () => [] as PermanenceRef[])
|
||||
try {
|
||||
const parsed = JSON.parse(raw)
|
||||
if (!Array.isArray(parsed)) return Array.from({ length: shotCount }, () => [] as PermanenceRef[])
|
||||
return Array.from({ length: shotCount }, (_, index) => normalizePermanenceRefs(parsed[index]))
|
||||
} catch {
|
||||
return Array.from({ length: shotCount }, () => [] as PermanenceRef[])
|
||||
}
|
||||
}
|
||||
|
||||
const SAMPLERS = new Set(['res_multistep', 'euler', 'dpmpp_2m'])
|
||||
const SCHEDULERS = new Set(['simple', 'ddim_uniform', 'sgm_uniform'])
|
||||
|
||||
@@ -84,11 +106,21 @@ export default defineEventHandler(async (event) => {
|
||||
if (!image && !textToVideo) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'An initial image is required' })
|
||||
}
|
||||
const prompt = (fields.prompt || '').trim()
|
||||
if (!prompt) {
|
||||
const promptRaw = (fields.prompt || '').trim()
|
||||
if (!promptRaw) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'A motion prompt is required' })
|
||||
}
|
||||
const resolvedLocks = resolveGlobalLocks(fields.globalLocks || '', promptRaw)
|
||||
const prompt = resolvedLocks.prompt
|
||||
const globalLocks = resolvedLocks.locks
|
||||
const extensions = parseExtensions(fields.extensions)
|
||||
const permanenceRefs = parseFamilyPermanenceRefs(fields.permanenceRefs)
|
||||
const shotPermanenceRefs = parseShotPermanenceRefs(fields.shotPermanenceRefs, 1 + extensions.length)
|
||||
for (const [index, item] of extensions.entries()) {
|
||||
if (!shotPermanenceRefs[index + 1]?.length && item.permanenceRefs?.length) {
|
||||
shotPermanenceRefs[index + 1] = item.permanenceRefs
|
||||
}
|
||||
}
|
||||
const useIdentityRefs = workflow === 'v2' && !textToVideo && !isLtxWorkflow(workflow) && fields.useIdentityRefs === 'true'
|
||||
const { width, height } = resolveOutputSize(
|
||||
fields.aspect,
|
||||
@@ -180,7 +212,10 @@ export default defineEventHandler(async (event) => {
|
||||
folderLocked,
|
||||
referenceStillIds,
|
||||
extensions,
|
||||
queueAutoRun
|
||||
queueAutoRun,
|
||||
globalLocks: globalLocks || undefined,
|
||||
permanenceRefs: permanenceRefs.length ? permanenceRefs : undefined,
|
||||
shotPermanenceRefs: shotPermanenceRefs.some(item => item.length) ? shotPermanenceRefs : undefined
|
||||
}
|
||||
})
|
||||
await kickStudioQueue()
|
||||
|
||||
Reference in New Issue
Block a user