refactor: use unified get_media_dir() to get media path

This commit is contained in:
Shiniese 2026-04-02 15:30:42 +08:00 committed by Xubin Ren
parent 624f607872
commit 84c4ba7609
2 changed files with 4 additions and 5 deletions

View File

@ -7,6 +7,7 @@ from typing import Any
from nanobot.agent.tools.base import Tool from nanobot.agent.tools.base import Tool
from nanobot.utils.helpers import build_image_content_blocks, detect_image_mime from nanobot.utils.helpers import build_image_content_blocks, detect_image_mime
from nanobot.config.paths import get_media_dir
def _resolve_path( def _resolve_path(
@ -21,8 +22,7 @@ def _resolve_path(
p = workspace / p p = workspace / p
resolved = p.resolve() resolved = p.resolve()
if allowed_dir: if allowed_dir:
from nanobot.config.paths import get_runtime_subdir media_path = get_media_dir().resolve()
media_path = get_runtime_subdir("media").resolve()
all_dirs = [allowed_dir] + [media_path] + (extra_allowed_dirs or []) all_dirs = [allowed_dir] + [media_path] + (extra_allowed_dirs or [])
if not any(_is_under(resolved, d) for d in all_dirs): if not any(_is_under(resolved, d) for d in all_dirs):
raise PermissionError(f"Path {path} is outside allowed directory {allowed_dir}") raise PermissionError(f"Path {path} is outside allowed directory {allowed_dir}")

View File

@ -10,6 +10,7 @@ from typing import Any
from loguru import logger from loguru import logger
from nanobot.agent.tools.base import Tool from nanobot.agent.tools.base import Tool
from nanobot.config.paths import get_media_dir
class ExecTool(Tool): class ExecTool(Tool):
@ -184,9 +185,7 @@ class ExecTool(Tool):
except Exception: except Exception:
continue continue
from nanobot.config.paths import get_runtime_subdir media_path = get_media_dir().resolve()
media_path = get_runtime_subdir("media").resolve()
if (p.is_absolute() if (p.is_absolute()
and cwd_path not in p.parents and cwd_path not in p.parents
and p != cwd_path and p != cwd_path