diff --git a/backend/api/routes/backup_api.py b/backend/api/routes/backup_api.py index 797350f3f..96233abed 100644 --- a/backend/api/routes/backup_api.py +++ b/backend/api/routes/backup_api.py @@ -27,12 +27,10 @@ def post(self): if password is None: raise ValueError("Password is required") - # Generate the key - key = generate_key(password) - try: + # Backup the database backup_unencrypted = backup_database() - backup_encrypted = encrypt_backup(backup_unencrypted, key) + backup_encrypted = encrypt_backup(backup_unencrypted, generate_key(password)) except InvalidToken: return { "message": "Invalid password" }, 400 @@ -63,6 +61,8 @@ def post(self): backup_file = request.files["backup"] password = request.form.get("password", None) + print(password) + # Check if the file exists if not backup_file: raise FileNotFoundError("File not found") @@ -71,20 +71,15 @@ def post(self): if password is None: raise ValueError("Password is required") - # Decrypt the backup - data = None - try: + # Decrypt the backup data = decrypt_backup(backup_file.read(), generate_key(password)) except InvalidToken: - return { "error": "Invalid password" }, 400 - - if data is None: - return { "error": "An unknown error occurred" } + return { "message": "Invalid password" }, 400 # Restore the backup - if not restore_database(data): - return { "error": "An unknown error occurred" } + if data is None or not restore_database(data): + return { "message": "An unknown error occurred" }, 400 # Return the response return { "message": "Backup restored successfully" } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 56d00559c..2c38efb2f 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,6 +1,6 @@