Add save image browse and external preview

This commit is contained in:
2026-08-05 13:15:39 +00:00
parent 17f7adba65
commit 8191dabb61
4 changed files with 86 additions and 5 deletions
+34
View File
@@ -1,6 +1,7 @@
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,
@@ -17,4 +18,37 @@ NODE_DISPLAY_NAME_MAPPINGS.update(IMAGE_NODE_DISPLAY_NAME_MAPPINGS)
WEB_DIRECTORY = "./js"
try:
import os
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:
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
root.attributes("-topmost", True)
selected = filedialog.askdirectory(
initialdir=str(_request.query.get("path", "") or "") or None
)
root.destroy()
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"]