DungeonCrawler/comfyui-audio/comfyui_audiocraft/__init__.py
Andre 8743133c43 AudioManager: Auto-Refresh nach jeder Generierung
Dateiliste wird jetzt per API (/audiocraft/list) geladen
statt über Node-Execution. Aktualisiert sich automatisch
nach jeder Generierung. Refresh-Button für manuelles Update.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 20:26:34 +01:00

51 lines
1.9 KiB
Python

from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
import os
from aiohttp import web
import server
WEB_DIRECTORY = "./web"
# API-Endpoint zum Löschen einzelner Audio-Dateien
@server.PromptServer.instance.routes.post("/audiocraft/delete")
async def delete_audio_file(request):
data = await request.json()
filename = data.get("filename", "")
if not filename or ".." in filename or "/" in filename or "\\" in filename:
return web.json_response({"error": "Ungueltiger Dateiname"}, status=400)
audio_dir = "/app/ComfyUI/output/audio"
filepath = os.path.join(audio_dir, filename)
if not os.path.exists(filepath):
return web.json_response({"error": "Datei nicht gefunden"}, status=404)
os.remove(filepath)
# Auch die zugehörige upsampled Version löschen falls vorhanden
base = filename.replace(".wav", "")
for f in os.listdir(audio_dir):
if f.startswith(base) and f != filename and f.endswith(".wav"):
os.remove(os.path.join(audio_dir, f))
return web.json_response({"ok": True, "deleted": filename})
# API-Endpoint zum Auflisten aller Audio-Dateien
@server.PromptServer.instance.routes.get("/audiocraft/list")
async def list_audio_files(request):
audio_dir = "/app/ComfyUI/output/audio"
if not os.path.exists(audio_dir):
return web.json_response({"files": [], "summary": "Kein Audio-Ordner"})
files = []
total_size = 0
for f in sorted(os.listdir(audio_dir)):
if f.endswith(".wav"):
fpath = os.path.join(audio_dir, f)
size = os.path.getsize(fpath)
total_size += size
files.append({"name": f, "size_mb": round(size / 1024 / 1024, 2)})
summary = f"{len(files)} Dateien | {total_size / 1024 / 1024:.1f} MB"
return web.json_response({"files": files, "summary": summary})
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]