forked from test2/Amnezia-Web-Panel-main
Fix Internal Server Error after SSH server add (server_info must be a dict).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+31
-4
@@ -94,6 +94,33 @@ def _merge_settings(raw: Optional[dict]) -> dict:
|
||||
return settings
|
||||
|
||||
|
||||
def _as_dict(value, default=None):
|
||||
"""Coerce JSONB / legacy values to a plain dict."""
|
||||
if default is None:
|
||||
default = {}
|
||||
if value is None:
|
||||
return dict(default)
|
||||
if isinstance(value, dict):
|
||||
return dict(value)
|
||||
# Legacy: ssh.test_connection() used to return a plain string
|
||||
if isinstance(value, str):
|
||||
text = value.strip()
|
||||
if not text:
|
||||
return dict(default)
|
||||
if text.startswith('{') or text.startswith('['):
|
||||
try:
|
||||
parsed = json.loads(text)
|
||||
if isinstance(parsed, dict):
|
||||
return parsed
|
||||
except Exception:
|
||||
pass
|
||||
return {'raw': text}
|
||||
try:
|
||||
return dict(value)
|
||||
except Exception:
|
||||
return {'raw': str(value)}
|
||||
|
||||
|
||||
def _row_to_server(row) -> dict:
|
||||
return {
|
||||
'name': row['name'] or '',
|
||||
@@ -102,8 +129,8 @@ def _row_to_server(row) -> dict:
|
||||
'username': row['username'] or '',
|
||||
'password': row['password'],
|
||||
'private_key': row['private_key'],
|
||||
'server_info': dict(row['server_info'] or {}),
|
||||
'protocols': dict(row['protocols'] or {}),
|
||||
'server_info': _as_dict(row['server_info']),
|
||||
'protocols': _as_dict(row['protocols']),
|
||||
}
|
||||
|
||||
|
||||
@@ -241,8 +268,8 @@ def save_data(data: dict) -> None:
|
||||
server.get('username') or '',
|
||||
server.get('password'),
|
||||
server.get('private_key'),
|
||||
Jsonb(server.get('server_info') or {}),
|
||||
Jsonb(server.get('protocols') or {}),
|
||||
Jsonb(_as_dict(server.get('server_info'))),
|
||||
Jsonb(_as_dict(server.get('protocols'))),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user