diff --git a/nas-media-player.py b/nas-media-player.py index 82543c4..c938e69 100644 --- a/nas-media-player.py +++ b/nas-media-player.py @@ -261,9 +261,11 @@ async def read_root(): @app.get("/api/directories") -async def get_directories(): - def traverse(path: Path, rel_path: str = "") -> List[Dict]: +async def get_directories(max_depth: int = 3): + def traverse(path: Path, rel_path: str = "", depth: int = 0) -> List[Dict]: items = [] + if depth >= max_depth: + return items # 超过深度限制,返回空列表 try: for d in sorted(path.iterdir(), key=lambda x: _natural_sort_key(x.name)): if d.is_dir() and not d.name.startswith('.'): @@ -273,7 +275,7 @@ async def get_directories(): "path": sub_rel, "type": "directory", "protected": is_protected_directory(sub_rel), - "children": traverse(d, sub_rel) + "children": traverse(d, sub_rel, depth + 1) }) except PermissionError: logger.warning(f"目录无读取权限: {path}") @@ -286,10 +288,12 @@ async def get_directories(): @app.get("/api/all-directories") -async def get_all_directories(): +async def get_all_directories(max_depth: int = 3): all_dirs = [] - def traverse(path: Path, rel_path: str = ""): + def traverse(path: Path, rel_path: str = "", depth: int = 0): + if depth >= max_depth: + return # 超过深度限制,停止遍历 all_dirs.append({ "name": rel_path if rel_path else "主目录", "path": rel_path, @@ -299,7 +303,7 @@ async def get_all_directories(): for d in sorted(path.iterdir(), key=lambda x: _natural_sort_key(x.name)): if d.is_dir() and not d.name.startswith('.'): sub_rel = f"{rel_path}/{d.name}" if rel_path else d.name - traverse(d, sub_rel) + traverse(d, sub_rel, depth + 1) except PermissionError: logger.warning(f"目录无读取权限: {path}") except Exception as e: diff --git a/override.py b/override.py index 022aa61..cbc12af 100644 --- a/override.py +++ b/override.py @@ -279,9 +279,11 @@ async def read_root(): @app.get("/api/directories") -async def get_directories(): - def traverse(path: Path, rel_path: str = "") -> List[Dict]: +async def get_directories(max_depth: int = 3): + def traverse(path: Path, rel_path: str = "", depth: int = 0) -> List[Dict]: items = [] + if depth >= max_depth: + return items # 超过深度限制,返回空列表 try: for d in sorted(path.iterdir(), key=lambda x: _natural_sort_key(x.name)): if d.is_dir() and not d.name.startswith('.'): @@ -291,7 +293,7 @@ async def get_directories(): "path": sub_rel, "type": "directory", "protected": is_protected_directory(sub_rel), - "children": traverse(d, sub_rel) + "children": traverse(d, sub_rel, depth + 1) }) except PermissionError: logger.warning(f"目录无读取权限: {path}") @@ -304,10 +306,12 @@ async def get_directories(): @app.get("/api/all-directories") -async def get_all_directories(): +async def get_all_directories(max_depth: int = 3): all_dirs = [] - def traverse(path: Path, rel_path: str = ""): + def traverse(path: Path, rel_path: str = "", depth: int = 0): + if depth >= max_depth: + return # 超过深度限制,停止遍历 all_dirs.append({ "name": rel_path if rel_path else "主目录", "path": rel_path, @@ -317,7 +321,7 @@ async def get_all_directories(): for d in sorted(path.iterdir(), key=lambda x: _natural_sort_key(x.name)): if d.is_dir() and not d.name.startswith('.'): sub_rel = f"{rel_path}/{d.name}" if rel_path else d.name - traverse(d, sub_rel) + traverse(d, sub_rel, depth + 1) except PermissionError: logger.warning(f"目录无读取权限: {path}") except Exception as e: diff --git a/releases/nas-media-player-arm64 b/releases/nas-media-player-arm64 deleted file mode 100755 index 5e25608..0000000 Binary files a/releases/nas-media-player-arm64 and /dev/null differ diff --git a/releases/nas-media-player-armhf b/releases/nas-media-player-armhf deleted file mode 100755 index afe7669..0000000 Binary files a/releases/nas-media-player-armhf and /dev/null differ diff --git a/zhinan.html b/zhinan.html index b633998..8312dbc 100644 --- a/zhinan.html +++ b/zhinan.html @@ -194,7 +194,7 @@
GET /api/directories?max_depth=5(扫描5层)。如需永久调整默认深度,请修改程序代码中的默认参数。
+ VIDEO_ROOT变量,修改为新的目录路径,保存后重启服务即可生效(需确保新目录有读写权限)。VIDEO_ROOT变量,修改为新的目录路径,保存后重启服务即可生效(需确保新目录有读写权限)。/opt/nas-media-player/main.py(改为8888端口),同时需确保新端口未被占用且防火墙已开放。/opt/nas-media-player/override.py(改为8888端口),同时需确保新端口未被占用且防火墙已开放。