From ff3822b4f9bd44babc5c4c95e17325409c5cdbae Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 6 Dec 2025 23:02:42 +0100 Subject: [PATCH] dirs? --- modules/active_modifier.py | 3 +-- modules/web.py | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/active_modifier.py b/modules/active_modifier.py index 663b212..008fa49 100644 --- a/modules/active_modifier.py +++ b/modules/active_modifier.py @@ -120,7 +120,6 @@ class Module(ActiveModifier): return {"status": "ok", "message": f"{len(songs_to_add)} songs added."} elif data.get("action") == "get_toplay": with self.file_lock: - with open("/tmp/radioPlayer_toplay", "r") as f: - return {"status": "ok", "data": [i.strip() for i in f.readlines() if i.strip()]} + with open("/tmp/radioPlayer_toplay", "r") as f: return {"status": "ok", "data": [i.strip() for i in f.readlines() if i.strip()]} activemod = Module() \ No newline at end of file diff --git a/modules/web.py b/modules/web.py index 9523963..62d7815 100644 --- a/modules/web.py +++ b/modules/web.py @@ -4,7 +4,9 @@ import threading, uuid, time from functools import partial from http.server import BaseHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn -from . import Track, PlayerModule +from . import Track, PlayerModule, Path + +MAIN_PATH_DIR = Path("/home/user/mixes") class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" @@ -41,6 +43,10 @@ class APIHandler(BaseHTTPRequestHandler): else: rdata = {"error": "Request to active module timed out"} code = 504 # Gateway Timeout + elif self.path == "/api/dirs": + return {"base": str(MAIN_PATH_DIR), "files": [i.name for i in list(MAIN_PATH_DIR.iterdir())]} + elif self.path.startswith("/api/dir/"): + return [i.name for i in (MAIN_PATH_DIR / self.path.removeprefix("/api/dir/").removesuffix("/")).iterdir() if i.is_file()] else: rdata = {"error": "not found"} self.send_response(code)