from .dumas_image_nodes import ( NODE_CLASS_MAPPINGS as IMAGE_NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as IMAGE_NODE_DISPLAY_NAME_MAPPINGS, resolve_serve_token, ) from .dumas_json_nodes import ( NODE_CLASS_MAPPINGS as JSON_NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as JSON_NODE_DISPLAY_NAME_MAPPINGS, ) NODE_CLASS_MAPPINGS = {} NODE_CLASS_MAPPINGS.update(JSON_NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(IMAGE_NODE_CLASS_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS.update(JSON_NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(IMAGE_NODE_DISPLAY_NAME_MAPPINGS) WEB_DIRECTORY = "./js" try: import os import subprocess import sys from aiohttp import web from server import PromptServer @PromptServer.instance.routes.get("/dumas/api/save_image/file") async def dumas_save_image_file(request): path = resolve_serve_token(request.query.get("t", "")) if not path or not os.path.isfile(path): return web.Response(status=404, text="unknown or expired preview token") return web.FileResponse(path) @PromptServer.instance.routes.get("/dumas/api/pick_directory") async def dumas_pick_directory(request): try: if sys.platform != "win32": return web.json_response({"ok": False, "message": "Native folder picker is only available on Windows right now."}) start_path = str(request.query.get("path", "") or "").strip() if start_path and not os.path.isdir(start_path): start_path = "" ps_lines = [ "Add-Type -AssemblyName System.Windows.Forms", "$dialog = New-Object System.Windows.Forms.FolderBrowserDialog", '$dialog.Description = "Select a folder"', "$dialog.ShowNewFolderButton = $true", ] if start_path: escaped = start_path.replace("'", "''") ps_lines.append(f"$dialog.SelectedPath = '{escaped}'") ps_lines.extend( [ "if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {", " [Console]::OutputEncoding = [System.Text.Encoding]::UTF8", " Write-Output $dialog.SelectedPath", "}", ] ) command = "; ".join(ps_lines) result = subprocess.run( [ "powershell", "-NoProfile", "-STA", "-ExecutionPolicy", "Bypass", "-Command", command, ], capture_output=True, text=True, encoding="utf-8", errors="replace", check=False, ) selected = (result.stdout or "").strip() if not selected: return web.json_response({"ok": False, "cancelled": True}) return web.json_response({"ok": True, "path": selected}) except Exception as exc: return web.json_response({"ok": False, "message": str(exc)}) except Exception: pass __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]