Queue Generate with an immediate local card and stop blocking reload on library or object_info.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { readFileSync,writeFileSync,renameSync } from 'node:fs'
|
||||
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 { studio2LoraCatalog } from '../../utils/studio2/lora-catalog'
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const path = join(studio2Root(), `loras-${owner}.cache`)
|
||||
// Same live Comfy scan as Settings (/api/loras?fresh=1). Always fresh so CACHE_MS cannot freeze adds.
|
||||
const fresh = String(getQuery(event).fresh || '') === '1'
|
||||
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: true
|
||||
fresh
|
||||
})
|
||||
return { ...listed, ...studio2LoraCatalog(owner) }
|
||||
})
|
||||
|
||||
@@ -1,25 +1,46 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { openSync, readSync, closeSync } from 'node:fs'
|
||||
import { execFile } from 'node:child_process'
|
||||
import { promisify } from 'node:util'
|
||||
import { getClip, getStill, clipVideoPath, stillPath } from '../library'
|
||||
import { imageDimensions } from '../resolution'
|
||||
import { resolveSize } from '~/shared/studio2/input.mjs'
|
||||
const exec = promisify(execFile)
|
||||
|
||||
function readImageHeader(path: string, maxBytes = 65536) {
|
||||
const fd = openSync(path, 'r')
|
||||
try {
|
||||
const buf = Buffer.alloc(maxBytes)
|
||||
const n = readSync(fd, buf, 0, maxBytes, 0)
|
||||
return buf.subarray(0, n)
|
||||
} finally {
|
||||
closeSync(fd)
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveRequestSize(owner: string, request: any) {
|
||||
const video=['video','extend'].includes(request.mode)
|
||||
let dimensions:any
|
||||
const video = ['video', 'extend'].includes(request.mode)
|
||||
let dimensions: any
|
||||
if (video && request.startClipId) {
|
||||
getClip(owner,request.startClipId)
|
||||
const result=await exec('ffprobe',['-v','error','-select_streams','v:0','-show_entries','stream=width,height','-of','json',clipVideoPath(owner,request.startClipId)],{windowsHide:true,timeout:15000})
|
||||
dimensions=JSON.parse(result.stdout).streams?.[0]
|
||||
const clip = getClip(owner, request.startClipId)
|
||||
if (clip.width && clip.height) {
|
||||
dimensions = { width: clip.width, height: clip.height }
|
||||
} else {
|
||||
const result = await exec('ffprobe', ['-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'json', clipVideoPath(owner, request.startClipId)], { windowsHide: true, timeout: 15000 })
|
||||
dimensions = JSON.parse(result.stdout).streams?.[0]
|
||||
}
|
||||
} else {
|
||||
const id=request.imageAId || request.identityStillId
|
||||
const id = request.imageAId || request.identityStillId
|
||||
if (id) {
|
||||
getStill(owner,id)
|
||||
dimensions=imageDimensions(readFileSync(stillPath(owner,id)))
|
||||
const still = getStill(owner, id)
|
||||
if (still.width && still.height) {
|
||||
dimensions = { width: still.width, height: still.height }
|
||||
} else {
|
||||
// Header only — never read the full archive PNG into memory on Generate click
|
||||
dimensions = imageDimensions(readImageHeader(stillPath(owner, id)))
|
||||
}
|
||||
if (!dimensions) throw new Error('Cannot measure the source still.')
|
||||
}
|
||||
}
|
||||
if (video && request.startClipId && !dimensions?.width) throw new Error('Cannot measure the previous clip.')
|
||||
Object.assign(request.settings,resolveSize(request.settings.aspect,dimensions,undefined,request.engine))
|
||||
Object.assign(request.settings, resolveSize(request.settings.aspect, dimensions, undefined, request.engine))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user