From f66de3c822fe8f7f72f0229eab07e9d97d8f2ba2 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 16 May 2024 16:11:42 -0700 Subject: [PATCH] Added support for VHS upload directory node --- js/button/dependencies.js | 24 +++++++++++++++++++----- js/resource/local.js | 5 +++++ python/custom_routes.py | 12 ++++++++++++ python/upload/progress.py | 3 +++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/js/button/dependencies.js b/js/button/dependencies.js index e056fcb..61c1ff6 100644 --- a/js/button/dependencies.js +++ b/js/button/dependencies.js @@ -15,6 +15,13 @@ const isModelExtension = z => z.endsWith('.safetensors') || z.endsWith('.bin') || z.endsWith('.ckpt') +const isDirectory = async (path) => { + const { exists } = await local.validatePathDirectory({ + path + }) + return exists; +} + // Loops over different nodes, and // finds paths that ends in @@ -63,7 +70,7 @@ export const resolveDependencies = async (diff) => { if (isInputValuePotentialPath) { // Handle VHS video extensions - if (isVideoExtension(z)) { + if (isVideoExtension(z) || await isDirectory(z)) { const filename = extractFilename(z) filesToUpload.push(filename) @@ -102,11 +109,11 @@ export const resolveDependencies = async (diff) => { // it is in the /input folder. // Right now we only can upload files that is inside // ComfyUI's /input folder. - const invalid = await local.validatePaths({ + const { invalid_paths } = await local.validatePaths({ paths: filesToUpload }) - if(invalid.length > 0){ - throw new Error("Got invalid input paths") + if(invalid_paths.length > 0){ + throw new Error("Make sure the following file/folder names are inside your ComfyUI /input folder: " + invalid_paths.join(", ")) } return { @@ -151,8 +158,15 @@ export const pollSyncDependencies = async (taskId) => { function extractFilename(filepath) { + let _filepath = filepath; + const isDirectory = filepath.endsWith('/') + if (isDirectory) { + // remove the extra slash at the end + _filepath = filepath.slice(0, -1); + } + // Split the filepath by '/' - const parts = filepath.split('/'); + const parts = _filepath.split('/'); // Take the last part which represents the filename const filename = parts[parts.length - 1]; return filename; diff --git a/js/resource/local.js b/js/resource/local.js index deb027c..3e83596 100644 --- a/js/resource/local.js +++ b/js/resource/local.js @@ -35,6 +35,11 @@ const local = { validatePaths: { method: "POST", path: "/comfy-cloud/validate-input-path" + }, + + validatePathDirectory: { + method: "POST", + path: "/comfy-cloud/validate-path" } } diff --git a/python/custom_routes.py b/python/custom_routes.py index 6a8926d..4c7b112 100644 --- a/python/custom_routes.py +++ b/python/custom_routes.py @@ -47,6 +47,18 @@ async def validate_input_path(request): print("Error:", e) return web.json_response({ "error": e }, status=400) +@server.PromptServer.instance.routes.post("/comfy-cloud/validate-path") +async def validate_path_directory(request): + try: + data = await request.json() + input_path = data.get("path") + + exists = os.path.exists(input_path) + + return web.json_response({ "exists": exists }, status=200) + except Exception as e: + print("Error:", e) + return web.json_response({ "error": e }, status=400) @server.PromptServer.instance.routes.post("/comfy-cloud/validate-prompt") async def comfy_cloud_validate_prompt(request): diff --git a/python/upload/progress.py b/python/upload/progress.py index d49763f..d6f2c4a 100644 --- a/python/upload/progress.py +++ b/python/upload/progress.py @@ -10,6 +10,9 @@ class FileProgress: progress_dict: Dict[str, FileProgress] = {} def progress_update(filename, value, max): + # filename can be PosixPath + filename = str(filename) + progress = progress_dict.get(filename, FileProgress(0, 0)) progress.value = value progress.max = max