From 778ea089978d85f058e21237ec62dcf027607bbf Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 23 Feb 2025 06:52:15 +0800 Subject: [PATCH] Fix symbolic links issue --- config.py | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/config.py b/config.py index 23f821b1..97a55324 100644 --- a/config.py +++ b/config.py @@ -109,32 +109,13 @@ class Config: if not preview_path: return "" - # 获取真实路径和规范化路径 - real_preview_path = os.path.realpath(preview_path) - normalized_real_path = real_preview_path.replace(os.sep, '/') - normalized_preview_path = preview_path.replace(os.sep, '/') - - # 首先尝试使用原始路径查找路由 - for root_path, route in self._route_mappings.items(): - if normalized_preview_path.startswith(root_path): - relative_path = os.path.relpath(normalized_preview_path, root_path) + real_path = os.path.realpath(preview_path).replace(os.sep, '/') + + for path, route in self._route_mappings.items(): + if real_path.startswith(path): + relative_path = os.path.relpath(real_path, path) return f'{route}/{relative_path.replace(os.sep, "/")}' - - # 如果没找到,尝试使用真实路径查找路由 - for root_path, route in self._route_mappings.items(): - if normalized_real_path.startswith(root_path): - relative_path = os.path.relpath(normalized_real_path, root_path) - return f'{route}/{relative_path.replace(os.sep, "/")}' - - # 如果还没找到,尝试使用路径映射 - mapped_path = self.map_path_to_link(real_preview_path) - normalized_mapped_path = mapped_path.replace(os.sep, '/') - - for root_path, route in self._route_mappings.items(): - if normalized_mapped_path.startswith(root_path): - relative_path = os.path.relpath(normalized_mapped_path, root_path) - return f'{route}/{relative_path.replace(os.sep, "/")}' - + return "" # Global config instance