Add ACE-Step music generation to the studio and library.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -243,6 +243,58 @@ function findVideo(value: unknown, depth = 0): { filename: string; subfolder: st
|
||||
return null
|
||||
}
|
||||
|
||||
function isAudioFile(item: { filename?: string; format?: string } | null | undefined) {
|
||||
if (!item) return false
|
||||
const name = String(item.filename || '').toLowerCase()
|
||||
const format = String(item.format || '').toLowerCase()
|
||||
return name.endsWith('.wav') || name.endsWith('.flac') || name.endsWith('.mp3') || name.endsWith('.ogg') || name.endsWith('.opus')
|
||||
|| format.includes('audio') || format.includes('wav') || format.includes('flac')
|
||||
}
|
||||
|
||||
function normalizeAudio(item: { filename?: string; subfolder?: string; type?: string }) {
|
||||
return {
|
||||
filename: String(item.filename),
|
||||
subfolder: String(item.subfolder || ''),
|
||||
type: String(item.type || 'output')
|
||||
}
|
||||
}
|
||||
|
||||
function findAudio(value: unknown, depth = 0): { filename: string; subfolder: string; type: string } | null {
|
||||
if (!value || typeof value !== 'object' || depth > 8) return null
|
||||
if (Array.isArray(value)) {
|
||||
const files = value.filter((item): item is { filename?: string; format?: string; subfolder?: string; type?: string } => Boolean(item && typeof item === 'object'))
|
||||
const match = files.find(item => {
|
||||
const name = String(item.filename || '').toLowerCase()
|
||||
return name.endsWith('.flac') || name.endsWith('.wav')
|
||||
}) || files.find(isAudioFile)
|
||||
if (match?.filename) return normalizeAudio(match)
|
||||
for (const item of value) {
|
||||
const nested = findAudio(item, depth + 1)
|
||||
if (nested) return nested
|
||||
}
|
||||
return null
|
||||
}
|
||||
const record = value as { filename?: string; format?: string; subfolder?: string; type?: string }
|
||||
if (record.filename && isAudioFile(record)) return normalizeAudio(record)
|
||||
for (const nested of Object.values(value as Record<string, unknown>)) {
|
||||
const found = findAudio(nested, depth + 1)
|
||||
if (found) return found
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function extractAudio(history: Record<string, unknown> | null, promptId: string) {
|
||||
if (!history) return null
|
||||
const wrapped = history[promptId] as { outputs?: Record<string, unknown> } | undefined
|
||||
if (wrapped) {
|
||||
return findAudio(wrapped.outputs || {}) || findAudio(wrapped)
|
||||
}
|
||||
if ((history as { outputs?: unknown }).outputs) {
|
||||
return findAudio((history as { outputs?: unknown }).outputs) || findAudio(history)
|
||||
}
|
||||
return findAudio(history)
|
||||
}
|
||||
|
||||
export function extractVideo(history: Record<string, unknown> | null, promptId: string) {
|
||||
if (!history) return null
|
||||
const wrapped = history[promptId] as { outputs?: Record<string, unknown> } | undefined
|
||||
|
||||
Reference in New Issue
Block a user