From 7de5a5ca9c220e5ccbe60729f83f79fdce73807f Mon Sep 17 00:00:00 2001 From: jimpi-dev Date: Fri, 13 Mar 2026 00:22:24 +0100 Subject: [PATCH] add functions for calc file sizes for better project mgt on workflowui app --- pyproject.toml | 2 +- routes.py | 39 +++++++++++++++++++++++++++++++++++++++ version_info.py | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7c3bb53..b3e46d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "WorkflowUIPlugin" description = "This custom node is a plugin for: WorkflowUI Application, found here: https://github.com/jimpi-dev/WorkflowUI" -version = "1.0.10" +version = "1.0.11" license = { file = "LICENSE" } [project.urls] diff --git a/routes.py b/routes.py index 5ea4f38..3c2e61e 100644 --- a/routes.py +++ b/routes.py @@ -314,6 +314,44 @@ async def _handle_list(request: web.Request) -> web.Response: return web.json_response({"type": folder_type, "subfolder": subfolder, "files": data}) +def _batch_output_sizes(groups: list) -> list[int]: + result = [] + for group in groups: + if not isinstance(group, list): + result.append(0) + continue + total = 0 + for ent in group: + if not isinstance(ent, dict): + continue + subfolder = (ent.get("subfolder") or "").strip() + filename = (ent.get("filename") or "").strip() + if not filename: + continue + full, err = _resolve_media_path("output", subfolder, filename) + if err or not full: + continue + try: + if os.path.isfile(full): + total += os.stat(full).st_size + except OSError: + pass + result.append(total) + return result + + +async def _handle_batch_output_sizes(request: web.Request) -> web.Response: + try: + body = await request.json() + except Exception: + return web.json_response({"error": "Invalid JSON"}, status=400) + groups = body.get("groups") if isinstance(body, dict) else None + if not isinstance(groups, list): + return web.json_response({"error": "Missing or invalid 'groups' array"}, status=400) + sizes = _batch_output_sizes(groups) + return web.json_response({"sizes": sizes}) + + def _tree_dir(folder_type: str, subfolder: str) -> tuple[dict | None, str | None]: if folder_type not in MEDIA_TYPES: return None, "Invalid type" @@ -511,6 +549,7 @@ def register_routes(): routes.post("/workflowui/media/upload")(_handle_upload) routes.get("/workflowui/media/view")(_handle_view) routes.get("/workflowui/media/list")(_handle_list) + routes.post("/workflowui/media/batch_output_sizes")(_handle_batch_output_sizes) routes.get("/workflowui/media/tree")(_handle_tree) routes.get("/workflowui/media/capabilities")(_handle_capabilities) routes.get("/workflowui/version_info")(_handle_version_info) diff --git a/version_info.py b/version_info.py index 405db0e..42e331a 100644 --- a/version_info.py +++ b/version_info.py @@ -4,7 +4,7 @@ import json import re from pathlib import Path -__version__ = "1.0.10" +__version__ = "1.0.11" _PLUGIN_DIR = Path(__file__).resolve().parent _CUSTOM_NODES_DIR = _PLUGIN_DIR.parent