fix(settings): restore legacy settings aliases

This commit is contained in:
pixelpaws
2025-10-08 09:54:36 +08:00
parent a726cbea1e
commit 0ad92d00b3
6 changed files with 31 additions and 10 deletions

View File

@@ -23,6 +23,8 @@ logger = logging.getLogger(__name__)
# Check if we're in standalone mode # Check if we're in standalone mode
STANDALONE_MODE = 'nodes' not in sys.modules STANDALONE_MODE = 'nodes' not in sys.modules
settings = get_settings_manager()
class LoraManager: class LoraManager:
"""Main entry point for LoRA Manager plugin""" """Main entry point for LoRA Manager plugin"""
@@ -51,7 +53,7 @@ class LoraManager:
asyncio_logger.addFilter(ConnectionResetFilter()) asyncio_logger.addFilter(ConnectionResetFilter())
# Add static route for example images if the path exists in settings # Add static route for example images if the path exists in settings
example_images_path = get_settings_manager().get('example_images_path') example_images_path = settings.get('example_images_path')
logger.info(f"Example images path: {example_images_path}") logger.info(f"Example images path: {example_images_path}")
if example_images_path and os.path.exists(example_images_path): if example_images_path and os.path.exists(example_images_path):
app.router.add_static('/example_images_static', example_images_path) app.router.add_static('/example_images_static', example_images_path)

View File

@@ -15,6 +15,8 @@ from ..utils.usage_stats import UsageStats
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
settings = get_settings_manager()
class StatsRoutes: class StatsRoutes:
"""Route handlers for Statistics page and API endpoints""" """Route handlers for Statistics page and API endpoints"""
@@ -66,7 +68,7 @@ class StatsRoutes:
is_initializing = lora_initializing or checkpoint_initializing or embedding_initializing is_initializing = lora_initializing or checkpoint_initializing or embedding_initializing
# 获取用户语言设置 # 获取用户语言设置
settings_manager = get_settings_manager() settings_manager = settings
user_language = settings_manager.get('language', 'en') user_language = settings_manager.get('language', 'en')
# 设置服务端i18n语言 # 设置服务端i18n语言

View File

@@ -692,16 +692,24 @@ class SettingsManager:
_SETTINGS_MANAGER: Optional["SettingsManager"] = None _SETTINGS_MANAGER: Optional["SettingsManager"] = None
_SETTINGS_MANAGER_LOCK = Lock() _SETTINGS_MANAGER_LOCK = Lock()
# Legacy module-level alias for backwards compatibility with callers that
# monkeypatch ``py.services.settings_manager.settings`` during tests.
settings: Optional["SettingsManager"] = None
def get_settings_manager() -> "SettingsManager": def get_settings_manager() -> "SettingsManager":
"""Return the lazily initialised global :class:`SettingsManager`.""" """Return the lazily initialised global :class:`SettingsManager`."""
global _SETTINGS_MANAGER global _SETTINGS_MANAGER, settings
if settings is not None:
return settings
if _SETTINGS_MANAGER is None: if _SETTINGS_MANAGER is None:
with _SETTINGS_MANAGER_LOCK: with _SETTINGS_MANAGER_LOCK:
if _SETTINGS_MANAGER is None: if _SETTINGS_MANAGER is None:
_SETTINGS_MANAGER = SettingsManager() _SETTINGS_MANAGER = SettingsManager()
settings = _SETTINGS_MANAGER
return _SETTINGS_MANAGER return _SETTINGS_MANAGER
@@ -712,6 +720,7 @@ def reset_settings_manager() -> None:
directory before the manager touches the filesystem. directory before the manager touches the filesystem.
""" """
global _SETTINGS_MANAGER global _SETTINGS_MANAGER, settings
with _SETTINGS_MANAGER_LOCK: with _SETTINGS_MANAGER_LOCK:
_SETTINGS_MANAGER = None _SETTINGS_MANAGER = None
settings = None

View File

@@ -20,22 +20,22 @@ _preview_service = PreviewAssetService(
exif_utils=ExifUtils, exif_utils=ExifUtils,
) )
_METADATA_SYNC_SERVICE: MetadataSyncService | None = None _metadata_sync_service: MetadataSyncService | None = None
def _get_metadata_sync_service() -> MetadataSyncService: def _get_metadata_sync_service() -> MetadataSyncService:
"""Return the shared metadata sync service, initialising it lazily.""" """Return the shared metadata sync service, initialising it lazily."""
global _METADATA_SYNC_SERVICE global _metadata_sync_service
if _METADATA_SYNC_SERVICE is None: if _metadata_sync_service is None:
_METADATA_SYNC_SERVICE = MetadataSyncService( _metadata_sync_service = MetadataSyncService(
metadata_manager=MetadataManager, metadata_manager=MetadataManager,
preview_service=_preview_service, preview_service=_preview_service,
settings=get_settings_manager(), settings=get_settings_manager(),
default_metadata_provider_factory=get_default_metadata_provider, default_metadata_provider_factory=get_default_metadata_provider,
metadata_provider_selector=get_metadata_provider, metadata_provider_selector=get_metadata_provider,
) )
return _METADATA_SYNC_SERVICE return _metadata_sync_service
class MetadataUpdater: class MetadataUpdater:

View File

@@ -14,13 +14,15 @@ logger = logging.getLogger(__name__)
CURRENT_NAMING_VERSION = 2 # Increment this when naming conventions change CURRENT_NAMING_VERSION = 2 # Increment this when naming conventions change
settings = get_settings_manager()
class ExampleImagesMigration: class ExampleImagesMigration:
"""Handles migrations for example images naming conventions""" """Handles migrations for example images naming conventions"""
@staticmethod @staticmethod
async def check_and_run_migrations(): async def check_and_run_migrations():
"""Check if migrations are needed and run them in background""" """Check if migrations are needed and run them in background"""
root = get_settings_manager().get('example_images_path') root = settings.get('example_images_path')
if not root or not os.path.exists(root): if not root or not os.path.exists(root):
logger.debug("No example images path configured or path doesn't exist, skipping migrations") logger.debug("No example images path configured or path doesn't exist, skipping migrations")
return return

View File

@@ -65,6 +65,12 @@ def ensure_settings_file(logger: Optional[logging.Logger] = None) -> str:
logger = logger or _LOGGER logger = logger or _LOGGER
target_path = get_settings_file_path(create_dir=True) target_path = get_settings_file_path(create_dir=True)
preferred_dir = user_config_dir(APP_NAME, appauthor=False)
preferred_path = os.path.join(preferred_dir, "settings.json")
if os.path.abspath(target_path) != os.path.abspath(preferred_path):
os.makedirs(preferred_dir, exist_ok=True)
target_path = preferred_path
legacy_path = get_legacy_settings_path() legacy_path = get_legacy_settings_path()
if os.path.exists(legacy_path) and not os.path.exists(target_path): if os.path.exists(legacy_path) and not os.path.exists(target_path):