This commit is contained in:
teasiu
2026-05-01 18:06:23 +08:00
parent f92ab4bca9
commit 8d903d36f1
5 changed files with 27 additions and 15 deletions

View File

@@ -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:

View File

@@ -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:

Binary file not shown.

Binary file not shown.

View File

@@ -194,7 +194,7 @@
<h3>媒体播放操作</h3>
<ol>
<li>登录系统后,左侧/上方的目录选择下拉框中选择媒体文件所在的子目录</li>
<li>系统会自动扫描该目录下的所有支持格式媒体文件,并显示在媒体选择下拉框中</li>
<li>系统会自动扫描该目录下<strong>最多3层子目录</strong>的所有支持格式媒体文件,并显示在媒体选择下拉框中</li>
<li>选择要播放的文件:
<ul>
<li>方式一:直接点击媒体选择下拉框中的目标文件</li>
@@ -208,6 +208,10 @@
</ul>
</li>
</ol>
<div class="note">
<strong>目录扫描说明</strong><br>
为提升性能和响应速度,系统默认只扫描目录结构的<strong>前3层</strong>。如果您的媒体文件位于更深层的子目录中可以通过API参数调整扫描深度例如<code>GET /api/directories?max_depth=5</code>扫描5层。如需永久调整默认深度请修改程序代码中的默认参数。
</div>
</div>
</div>
@@ -374,7 +378,7 @@
</tr>
<tr>
<td>如何修改媒体根目录?</td>
<td>编辑后端主文件(/opt/nas-media-player/main.py中的<code>VIDEO_ROOT</code>变量,修改为新的目录路径,保存后重启服务即可生效(需确保新目录有读写权限)。</td>
<td>编辑后端主文件(/opt/nas-media-player/nas-media-player.py中的<code>VIDEO_ROOT</code>变量,修改为新的目录路径,保存后重启服务即可生效(需确保新目录有读写权限)。</td>
</tr>
<tr>
<td>加密目录的密码忘记了怎么办?</td>
@@ -394,7 +398,7 @@
</tr>
<tr>
<td>如何修改服务端口非8800</td>
<td>启动服务时修改端口参数,如<code>/opt/nas-media-player/main.py</code>改为8888端口同时需确保新端口未被占用且防火墙已开放。</td>
<td>启动服务时修改端口参数,如<code>/opt/nas-media-player/override.py</code>改为8888端口同时需确保新端口未被占用且防火墙已开放。</td>
</tr>
</table>
</div>