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
STANDALONE_MODE = 'nodes' not in sys.modules
settings = get_settings_manager()
class LoraManager:
"""Main entry point for LoRA Manager plugin"""
@@ -51,7 +53,7 @@ class LoraManager:
asyncio_logger.addFilter(ConnectionResetFilter())
# 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}")
if example_images_path and os.path.exists(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__)
settings = get_settings_manager()
class StatsRoutes:
"""Route handlers for Statistics page and API endpoints"""
@@ -66,7 +68,7 @@ class StatsRoutes:
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')
# 设置服务端i18n语言

View File

@@ -692,16 +692,24 @@ class SettingsManager:
_SETTINGS_MANAGER: Optional["SettingsManager"] = None
_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":
"""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:
with _SETTINGS_MANAGER_LOCK:
if _SETTINGS_MANAGER is None:
_SETTINGS_MANAGER = SettingsManager()
settings = _SETTINGS_MANAGER
return _SETTINGS_MANAGER
@@ -712,6 +720,7 @@ def reset_settings_manager() -> None:
directory before the manager touches the filesystem.
"""
global _SETTINGS_MANAGER
global _SETTINGS_MANAGER, settings
with _SETTINGS_MANAGER_LOCK:
_SETTINGS_MANAGER = None
settings = None

View File

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

View File

@@ -14,13 +14,15 @@ logger = logging.getLogger(__name__)
CURRENT_NAMING_VERSION = 2 # Increment this when naming conventions change
settings = get_settings_manager()
class ExampleImagesMigration:
"""Handles migrations for example images naming conventions"""
@staticmethod
async def check_and_run_migrations():
"""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):
logger.debug("No example images path configured or path doesn't exist, skipping migrations")
return

View File

@@ -65,6 +65,12 @@ def ensure_settings_file(logger: Optional[logging.Logger] = None) -> str:
logger = logger or _LOGGER
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()
if os.path.exists(legacy_path) and not os.path.exists(target_path):