AudioManager: Einzelne Dateien löschen per X-Button
API-Endpoint /audiocraft/delete im Backend. Löscht die Datei und die zugehörige upsampled Version. Gelöschte Zeilen werden ausgegraut. Stoppt Wiedergabe falls die Datei gerade spielt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5481a1e92f
commit
8768edc16c
2 changed files with 50 additions and 0 deletions
|
|
@ -1,5 +1,30 @@
|
|||
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})
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
|
||||
|
|
|
|||
|
|
@ -139,10 +139,35 @@ function buildContent(container, summary, files) {
|
|||
};
|
||||
};
|
||||
|
||||
const delBtn = document.createElement("button");
|
||||
delBtn.textContent = "\u2716";
|
||||
delBtn.title = "Loeschen";
|
||||
delBtn.style.cssText = "background:#533;border:none;color:#f66;cursor:pointer;padding:2px 6px;border-radius:3px;font-size:11px;margin-left:4px;";
|
||||
delBtn.onclick = async () => {
|
||||
// Stop if this file is playing
|
||||
if (activeBtn === playBtn) stopActive();
|
||||
try {
|
||||
const resp = await api.fetchApi("/audiocraft/delete", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({filename: f.name}),
|
||||
});
|
||||
if (resp.ok) {
|
||||
row.style.opacity = "0.3";
|
||||
row.style.pointerEvents = "none";
|
||||
delBtn.textContent = "\u2714";
|
||||
delBtn.style.color = "#888";
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Delete failed:", e);
|
||||
}
|
||||
};
|
||||
|
||||
row.appendChild(name);
|
||||
row.appendChild(size);
|
||||
row.appendChild(playBtn);
|
||||
row.appendChild(dlBtn);
|
||||
row.appendChild(delBtn);
|
||||
container.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue