feat: add API endpoint for fetching application settings and update frontend settings management

This commit is contained in:
Will Miao
2025-09-14 22:57:17 +08:00
parent 6b606a5cc8
commit 9366d3d2d0
6 changed files with 291 additions and 266 deletions

View File

@@ -88,6 +88,7 @@ class MiscRoutes:
@staticmethod
def setup_routes(app):
"""Register miscellaneous routes"""
app.router.add_get('/api/settings', MiscRoutes.get_settings)
app.router.add_post('/api/settings', MiscRoutes.update_settings)
app.router.add_get('/api/health-check', lambda request: web.json_response({'status': 'ok'}))
@@ -119,6 +120,47 @@ class MiscRoutes:
app.router.add_post('/api/remove-metadata-archive', MiscRoutes.remove_metadata_archive)
app.router.add_get('/api/metadata-archive-status', MiscRoutes.get_metadata_archive_status)
@staticmethod
async def get_settings(request):
"""Get application settings that should be synced to frontend"""
try:
# Define keys that should be synced from backend to frontend
sync_keys = [
'civitai_api_key',
'default_lora_root',
'default_checkpoint_root',
'default_embedding_root',
'base_model_path_mappings',
'download_path_templates',
'enable_metadata_archive_db',
'language',
'proxy_enabled',
'proxy_type',
'proxy_host',
'proxy_port',
'proxy_username',
'proxy_password'
]
# Build response with only the keys that should be synced
response_data = {}
for key in sync_keys:
value = settings.get(key)
if value is not None:
response_data[key] = value
return web.json_response({
'success': True,
'settings': response_data
})
except Exception as e:
logger.error(f"Error getting settings: {e}", exc_info=True)
return web.json_response({
'success': False,
'error': str(e)
}, status=500)
@staticmethod
async def update_settings(request):
"""Update application settings"""

View File

@@ -80,7 +80,6 @@ class SettingsManager:
"""Return default settings"""
return {
"civitai_api_key": "",
"show_only_sfw": False,
"language": "en",
"enable_metadata_archive_db": False, # Enable metadata archive database
"proxy_enabled": False, # Enable app-level proxy