Add custom nodes, Civitai loras (LFS), and vast.ai setup script
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Includes 30 custom nodes committed directly, 7 Civitai-exclusive loras stored via Git LFS, and a setup script that installs all dependencies and downloads HuggingFace-hosted models on vast.ai. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
72
custom_nodes/rgthree-comfy/src_web/common/utils_workflow.ts
Normal file
72
custom_nodes/rgthree-comfy/src_web/common/utils_workflow.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type {ISerialisedGraph} from "@comfyorg/frontend";
|
||||
import type {ComfyApiFormat} from "typings/comfy.js";
|
||||
|
||||
import {getResolver} from "./shared_utils.js";
|
||||
import {getPngMetadata, getWebpMetadata} from "./comfyui_shim.js";
|
||||
|
||||
/**
|
||||
* Parses the workflow JSON and do any necessary cleanup.
|
||||
*/
|
||||
function parseWorkflowJson(stringJson?: string) {
|
||||
stringJson = stringJson || "null";
|
||||
// Starting around August 2024 the serialized JSON started to get messy and contained `NaN` (for
|
||||
// an is_changed property, specifically). NaN is not parseable, so we'll get those on out of there
|
||||
// and cleanup anything else we need.
|
||||
stringJson = stringJson.replace(/:\s*NaN/g, ": null");
|
||||
return JSON.parse(stringJson);
|
||||
}
|
||||
|
||||
export async function tryToGetWorkflowDataFromEvent(
|
||||
e: DragEvent,
|
||||
): Promise<{workflow: ISerialisedGraph | null; prompt: ComfyApiFormat | null}> {
|
||||
let work;
|
||||
for (const file of e.dataTransfer?.files || []) {
|
||||
const data = await tryToGetWorkflowDataFromFile(file);
|
||||
if (data.workflow || data.prompt) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
const validTypes = ["text/uri-list", "text/x-moz-url"];
|
||||
const match = (e.dataTransfer?.types || []).find((t) => validTypes.find((v) => t === v));
|
||||
if (match) {
|
||||
const uri = e.dataTransfer!.getData(match)?.split("\n")?.[0];
|
||||
if (uri) {
|
||||
return tryToGetWorkflowDataFromFile(await (await fetch(uri)).blob());
|
||||
}
|
||||
}
|
||||
return {workflow: null, prompt: null};
|
||||
}
|
||||
|
||||
export async function tryToGetWorkflowDataFromFile(
|
||||
file: File | Blob,
|
||||
): Promise<{workflow: ISerialisedGraph | null; prompt: ComfyApiFormat | null}> {
|
||||
if (file.type === "image/png") {
|
||||
const pngInfo = await getPngMetadata(file);
|
||||
return {
|
||||
workflow: parseWorkflowJson(pngInfo?.workflow),
|
||||
prompt: parseWorkflowJson(pngInfo?.prompt),
|
||||
};
|
||||
}
|
||||
|
||||
if (file.type === "image/webp") {
|
||||
const pngInfo = await getWebpMetadata(file);
|
||||
// Support loading workflows from that webp custom node.
|
||||
const workflow = parseWorkflowJson(pngInfo?.workflow || pngInfo?.Workflow || "null");
|
||||
const prompt = parseWorkflowJson(pngInfo?.prompt || pngInfo?.Prompt || "null");
|
||||
return {workflow, prompt};
|
||||
}
|
||||
|
||||
if (file.type === "application/json" || (file as File).name?.endsWith(".json")) {
|
||||
const resolver = getResolver<{workflow: any; prompt: any}>();
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
const json = parseWorkflowJson(reader.result as string);
|
||||
const isApiJson = Object.values(json).every((v: any) => v.class_type);
|
||||
const prompt = isApiJson ? json : null;
|
||||
const workflow = !isApiJson && !json?.templates ? json : null;
|
||||
return {workflow, prompt};
|
||||
};
|
||||
return resolver.promise;
|
||||
}
|
||||
return {workflow: null, prompt: null};
|
||||
}
|
||||
Reference in New Issue
Block a user