diff --git a/__init__.py b/__init__.py index a9ba633..c5536e4 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS -WEB_DIRECTORY = './js' +WEB_DIRECTORY = './web' __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY'] diff --git a/js/node.js b/js/node.js deleted file mode 100644 index c41cc87..0000000 --- a/js/node.js +++ /dev/null @@ -1,79 +0,0 @@ -import { app } from "/scripts/app.js" -import { api } from "/scripts/api.js" - -app.registerExtension({ - name: "comfyui_davcha.DavchaLoadVideo", - async beforeRegisterNodeDef(nodeType, nodeData, app) { - if (!nodeData?.category?.startsWith("davcha")) { - return; - } - - if (nodeData.name == "DavchaLoadVideo") { - nodeType.prototype.onDragOver = function (e) { - if (e.dataTransfer && e.dataTransfer.items) { - return [...e.dataTransfer.items].some(f => f.kind === "file" && (f.type.startsWith("image/") || f.type.startsWith("video/"))); - } - }; - - - nodeType.prototype.onDragDrop = async function (e) { - const file = e.dataTransfer.files[0]; - - const body = new FormData(); - body.append("image", file); - // if (pasted) body.append("subfolder", "pasted"); - const resp = await api.fetchApi("/upload/image", { - method: "POST", - body - }); - const data = await resp.json(); - - this.widgets.find(w => w.name == 'path').value = data.name; - }; - } - - const update = function (node, option_value = null) { - const width = node.widgets.find(w => w.name == "width").value; - const height = node.widgets.find(w => w.name == "height").value; - const x = Array.from({ length: (width + 1) / 8 + 1 }, (_, i) => i * 8); - const y = Array.from({ length: (height + 1) / 8 + 1 }, (_, i) => i * 8); - - const lastX = x[x.length - 1]; - const lastY = y[y.length - 1]; - const ratio = lastX / lastY; - - const options = []; - - for (let i = 0; i < x.length; i++) { - for (let j = 0; j < y.length; j++) { - if (x[i] / y[j] === ratio && Math.round(lastX / x[i] * 100) / 100 === lastX / x[i]) { - options.push(`${x[i]}x${y[j]}: ${lastX / x[i]}`); - } - } - } - - const option = node.widgets.find(w => w.name == 'option') - option.options = { values: options }; - if (option_value !== null && options.indexOf(option_value) != -1) { - option.value = option_value; - } else { - option.value = options[0]; - } - } - - if (nodeData.name == 'DavchaEmptyLatentImage') { - const onNodeCreated = nodeType.prototype.onNodeCreated; - nodeType.prototype.onNodeCreated = function () { - onNodeCreated?.apply(this, arguments); - this.widgets.find(w => w.name == 'width').callback = () => update(this); - this.widgets.find(w => w.name == 'height').callback = () => update(this); - update(this); - }; - nodeType.prototype.onConfigure = function () { - const option_value = this.widgets.find(w => w.name == 'option').value; - update(this, option_value); - } - } - } - -}) \ No newline at end of file