Fix backup restore freezing the panel with loading feedback.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2793,27 +2793,30 @@ async def api_protocol_backup_create(request: Request, server_id: int, req: Prot
|
||||
return JSONResponse({'error': 'Forbidden'}, status_code=403)
|
||||
if not is_valid_protocol(req.protocol):
|
||||
return JSONResponse({'error': 'Unknown protocol'}, status_code=400)
|
||||
ssh = None
|
||||
try:
|
||||
data = load_data()
|
||||
data = await load_data_async()
|
||||
if server_id >= len(data['servers']):
|
||||
return JSONResponse({'error': 'Server not found'}, status_code=404)
|
||||
container = protocol_container_name(req.protocol)
|
||||
if not container:
|
||||
return JSONResponse({'error': 'Unknown protocol'}, status_code=400)
|
||||
server = data['servers'][server_id]
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
result = BackupManager(ssh).create_backup(req.protocol, container)
|
||||
|
||||
def _do_create():
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
try:
|
||||
return BackupManager(ssh).create_backup(req.protocol, container)
|
||||
finally:
|
||||
ssh.disconnect()
|
||||
|
||||
result = await asyncio.to_thread(_do_create)
|
||||
if result.get('status') == 'error':
|
||||
return JSONResponse({'error': result.get('message', 'Failed to create backup')}, status_code=500)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.exception("Error creating protocol backup")
|
||||
return JSONResponse({'error': str(e)}, status_code=500)
|
||||
finally:
|
||||
if ssh:
|
||||
ssh.disconnect()
|
||||
|
||||
|
||||
@app.post('/api/servers/{server_id}/backups/download', tags=["Protocols"])
|
||||
@@ -2898,27 +2901,30 @@ async def api_protocol_backup_restore(request: Request, server_id: int, req: Bac
|
||||
return JSONResponse({'error': 'Forbidden'}, status_code=403)
|
||||
if not is_valid_protocol(req.protocol):
|
||||
return JSONResponse({'error': 'Unknown protocol'}, status_code=400)
|
||||
ssh = None
|
||||
try:
|
||||
data = load_data()
|
||||
data = await load_data_async()
|
||||
if server_id >= len(data['servers']):
|
||||
return JSONResponse({'error': 'Server not found'}, status_code=404)
|
||||
container = protocol_container_name(req.protocol)
|
||||
if not container:
|
||||
return JSONResponse({'error': 'Unknown protocol'}, status_code=400)
|
||||
server = data['servers'][server_id]
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
result = BackupManager(ssh).restore_backup(req.protocol, container, req.filename)
|
||||
|
||||
def _do_restore():
|
||||
ssh = get_ssh(server)
|
||||
ssh.connect()
|
||||
try:
|
||||
return BackupManager(ssh).restore_backup(req.protocol, container, req.filename)
|
||||
finally:
|
||||
ssh.disconnect()
|
||||
|
||||
result = await asyncio.to_thread(_do_restore)
|
||||
if result.get('status') == 'error':
|
||||
return JSONResponse({'error': result.get('message', 'Failed to restore backup')}, status_code=500)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.exception("Error restoring protocol backup")
|
||||
return JSONResponse({'error': str(e)}, status_code=500)
|
||||
finally:
|
||||
if ssh:
|
||||
ssh.disconnect()
|
||||
|
||||
|
||||
@app.post('/api/servers/{server_id}/backups/export-clients', tags=["Protocols"])
|
||||
|
||||
Reference in New Issue
Block a user