Files

28 lines
1.2 KiB
JavaScript

import { app } from "../../scripts/app.js";
// Flake Generate outputs keep their prompt and workflow in
// .flake_metadata/<file name>.json next to them instead of inside the file
// (#479). Dropping one loads that workflow (#480); any other file, older
// outputs with an embedded workflow included, goes to ComfyUI's own handler.
const SIDECAR_TYPES = ["image/png", "image/webp", "image/jpeg", "video/mp4", "video/webm"];
async function sidecarWorkflow(file) {
if (!SIDECAR_TYPES.includes(file.type)) return null;
const r = await fetch(`/flakes/metadata?${new URLSearchParams({ filename: file.name, size: file.size })}`);
return r.ok ? (await r.json()).workflow : null;
}
app.registerExtension({
name: "comfyui-flakes.Metadata",
setup() {
const handleFile = app.handleFile;
app.handleFile = async function (file, ...args) {
const workflow = await sidecarWorkflow(file);
if (!workflow) return handleFile.call(this, file, ...args);
const [openSource, options] = args;
await this.loadGraphData(workflow, true, true, file.name.replace(/\.\w+$/, ""),
{ openSource, deferWarnings: options?.deferWarnings });
};
},
});