Add a Scale to 1 MP toggle on image edit before Klein.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -51,6 +51,34 @@ export async function comfyFetch(path: string, init?: RequestInit) {
|
||||
}
|
||||
}
|
||||
|
||||
/** true = installed, false = missing, null = Comfy unreachable / object_info failed */
|
||||
export async function comfyHasClassType(classType: string): Promise<boolean | null> {
|
||||
try {
|
||||
const res = await comfyFetch(`/object_info/${encodeURIComponent(classType)}`, {
|
||||
signal: AbortSignal.timeout(8000)
|
||||
})
|
||||
if (res.status === 404) return false
|
||||
if (!res.ok) return null
|
||||
const body = await res.json().catch(() => null)
|
||||
if (!body || typeof body !== 'object') return false
|
||||
const rec = body as Record<string, unknown>
|
||||
if (rec[classType] && typeof rec[classType] === 'object') return true
|
||||
return String(rec.name || rec.class_type || '') === classType
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const IMAGE_SCALE_TO_TOTAL_PIXELS = 'ImageScaleToTotalPixels'
|
||||
export const IMAGE_SCALE_MISSING_MESSAGE = 'Scale Image to Total Pixels (ImageScaleToTotalPixels) is not installed on Beast. Turn Scale to 1 MP off, or install the node.'
|
||||
|
||||
export async function assertImageScaleToTotalPixelsNode() {
|
||||
const present = await comfyHasClassType(IMAGE_SCALE_TO_TOTAL_PIXELS)
|
||||
if (present === false) {
|
||||
throw createError({ statusCode: 400, statusMessage: IMAGE_SCALE_MISSING_MESSAGE })
|
||||
}
|
||||
}
|
||||
|
||||
export async function uploadImage(file: { filename: string; data: Buffer; type?: string }, jobId?: string) {
|
||||
const body = new FormData()
|
||||
const blob = new Blob([new Uint8Array(file.data)], { type: file.type || 'application/octet-stream' })
|
||||
|
||||
Reference in New Issue
Block a user