mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
feat: Enhance get_preview_static_url to find the longest matching route for static URLs
This commit is contained in:
23
py/config.py
23
py/config.py
@@ -268,19 +268,26 @@ class Config:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def get_preview_static_url(self, preview_path: str) -> str:
|
def get_preview_static_url(self, preview_path: str) -> str:
|
||||||
"""Convert local preview path to static URL"""
|
|
||||||
if not preview_path:
|
if not preview_path:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
real_path = os.path.realpath(preview_path).replace(os.sep, '/')
|
real_path = os.path.realpath(preview_path).replace(os.sep, '/')
|
||||||
|
|
||||||
|
# Find longest matching path (most specific match)
|
||||||
|
best_match = ""
|
||||||
|
best_route = ""
|
||||||
|
|
||||||
for path, route in self._route_mappings.items():
|
for path, route in self._route_mappings.items():
|
||||||
if real_path.startswith(path):
|
if real_path.startswith(path) and len(path) > len(best_match):
|
||||||
relative_path = os.path.relpath(real_path, path).replace(os.sep, '/')
|
best_match = path
|
||||||
safe_parts = [urllib.parse.quote(part) for part in relative_path.split('/')]
|
best_route = route
|
||||||
safe_path = '/'.join(safe_parts)
|
|
||||||
return f'{route}/{safe_path}'
|
if best_match:
|
||||||
|
relative_path = os.path.relpath(real_path, best_match).replace(os.sep, '/')
|
||||||
|
safe_parts = [urllib.parse.quote(part) for part in relative_path.split('/')]
|
||||||
|
safe_path = '/'.join(safe_parts)
|
||||||
|
return f'{best_route}/{safe_path}'
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# Global config instance
|
# Global config instance
|
||||||
|
|||||||
Reference in New Issue
Block a user