diff --git a/py/lora_manager.py b/py/lora_manager.py index b763b0c6..97ebb781 100644 --- a/py/lora_manager.py +++ b/py/lora_manager.py @@ -10,6 +10,7 @@ from .routes.misc_routes import MiscRoutes from .routes.example_images_routes import ExampleImagesRoutes from .services.service_registry import ServiceRegistry from .services.settings_manager import settings +from pathlib import Path import logging import sys import os @@ -94,10 +95,14 @@ class LoraManager: route_path = f'/loras_static/link_{link_idx["lora"]}/preview' link_idx["lora"] += 1 - app.router.add_static(route_path, target_path) - logger.info(f"Added static route for link target {route_path} -> {target_path}") - config.add_route_mapping(target_path, route_path) - added_targets.add(target_path) + try: + app.router.add_static(route_path, Path(target_path).resolve(strict=False)) + logger.info(f"Added static route for link target {route_path} -> {target_path}") + config.add_route_mapping(target_path, route_path) + added_targets.add(target_path) + except Exception as e: + logger.warning(f"Failed to add static route on initialization for {target_path}: {e}") + continue # Add static route for plugin assets app.router.add_static('/loras_static', config.static_path) diff --git a/standalone.py b/standalone.py index 1af4751b..79c3bd8d 100644 --- a/standalone.py +++ b/standalone.py @@ -1,3 +1,4 @@ +from pathlib import Path import os import sys import json @@ -280,10 +281,14 @@ class StandaloneLoraManager(LoraManager): # Display path with forward slashes for consistency display_target = target_path.replace('\\', '/') - app.router.add_static(route_path, target_path) - logger.info(f"Added static route for link target {route_path} -> {display_target}") - config.add_route_mapping(target_path, route_path) - added_targets.add(norm_target) + try: + app.router.add_static(route_path, Path(target_path).resolve(strict=False)) + logger.info(f"Added static route for link target {route_path} -> {display_target}") + config.add_route_mapping(target_path, route_path) + added_targets.add(norm_target) + except Exception as e: + logger.warning(f"Failed to add static route on initialization for {target_path}: {e}") + continue # Add static route for plugin assets app.router.add_static('/loras_static', config.static_path)