fix(file-manager): preserve project/prompt prefix in nested directories
修复文件管理 API 中路径计算问题。当点击第三级目录时,由于 PROJECTS_DIR 是相对路径而 item 是绝对路径,导致 relative_to() 失败返回绝对路径,从而使前端丢失前缀。 使用 PROJECTS_DIR.resolve() 作为基准确保正确计算相对路径。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e00f99c5c5
commit
c808517f02
@ -107,6 +107,8 @@ async def list_files(path: str = "", recursive: bool = False):
|
||||
|
||||
def scan_directory(directory: Path, base_path: Path = PROJECTS_DIR) -> List[Dict[str, Any]]:
|
||||
items = []
|
||||
# 使用解析后的绝对路径作为基准
|
||||
base_resolved = PROJECTS_DIR.resolve()
|
||||
try:
|
||||
for item in directory.iterdir():
|
||||
# 跳过隐藏文件
|
||||
@ -115,10 +117,14 @@ async def list_files(path: str = "", recursive: bool = False):
|
||||
|
||||
# 计算相对于项目根目录的相对路径
|
||||
try:
|
||||
relative_path = item.relative_to(PROJECTS_DIR)
|
||||
relative_path = item.relative_to(base_resolved)
|
||||
except ValueError:
|
||||
# 如果无法计算相对路径,使用绝对路径
|
||||
relative_path = item
|
||||
# 如果无法计算相对路径,尝试计算相对于当前目录的路径
|
||||
try:
|
||||
relative_path = item.relative_to(directory.resolve().parent)
|
||||
except ValueError:
|
||||
# 最后尝试直接使用相对路径
|
||||
relative_path = item
|
||||
|
||||
stat = item.stat()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user