From fe42e8e29cd8a9b9f6d53636b0d06fbeb1aa73e3 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj <7842232+AbdullahAlfaraj@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:34:46 +0300 Subject: [PATCH] add support for comfyapi --- typescripts/comfyui/comfyapi.ts | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 typescripts/comfyui/comfyapi.ts diff --git a/typescripts/comfyui/comfyapi.ts b/typescripts/comfyui/comfyapi.ts new file mode 100644 index 0000000..37d0f1b --- /dev/null +++ b/typescripts/comfyui/comfyapi.ts @@ -0,0 +1,71 @@ +import settings_tab from '../settings/settings' +import { requestGet } from '../util/ts/api' + +class ComfyAPI { + private object_info: Record = {} + comfy_url: string + constructor(comfy_url: string) { + this.comfy_url = comfy_url + } + async init() { + this.object_info = await this.getObjectInfo(this.comfy_url) + } + setUrl(comfy_url: string) { + this.comfy_url = comfy_url + } + async refresh() { + this.object_info = await this.getObjectInfo(this.comfy_url) + } + + async getObjectInfo(comfy_url: string) { + try { + const object_info = await requestGet(`${comfy_url}/object_info`) + return object_info + } catch (e) { + console.error(e) + } + } + private getData(path: string[]): any[] { + let data = [] + try { + let obj = this.object_info + for (const p of path) { + obj = obj[p] + } + data = obj[0] + } catch (e) { + console.error( + `Failed to get data from path ${path.join('.')}: ${e}` + ) + } + return data + } + + getModels(): any[] { + return this.getData([ + 'CheckpointLoader', + 'input', + 'required', + 'ckpt_name', + ]) + } + + getVAEs(): any[] { + return this.getData(['VAELoader', 'input', 'required', 'vae_name']) + } + getSamplerNames(): string[] { + return this.getData(['KSampler', 'input', 'required', 'sampler_name']) + } + getHiResUpscalers(): string[] { + return this.getData([ + 'LatentUpscaleBy', + 'input', + 'required', + 'upscale_method', + ]) + } +} +export default { + ComfyAPI, + comfy_api: new ComfyAPI(settings_tab.store.data.comfy_url), +}