Skip to content

Commit 08a8758

Browse files
authored
Merge pull request #93 from x10102/master
Bug fixes for backup module
2 parents 93d6b51 + 52b6ddf commit 08a8758

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

blueprints/autobackup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def setup_backup_route(setup_state):
131131
setup_state.app.add_url_rule('/backup/start', view_func=login_required(backup))
132132

133133
def finish_backup():
134+
global statuses
134135
if Backup.get_or_none(Backup.is_finished == False) is None:
135136
# Don't think that this can actually happen but it's better to handle it regardless
136137
warning("No backups to finish!")
@@ -178,7 +179,7 @@ def finish_backup():
178179
backup_done_message += f"Kontrolní součet archivu je {hash}\n\n"
179180
backup_done_message += "Administrace Záznamů a Informační Bezpečnosti vám přeje hezký den!```" # Be polite :3
180181
webhook.send_text(backup_done_message)
181-
statuses.clear()
182+
statuses = {}
182183
Backup.update(is_finished=True).where(Backup.is_finished == False).execute()
183184

184185
@AutobackupController.route('/backups', methods=["GET"])
@@ -202,6 +203,9 @@ def backup_delete(backup_id: int):
202203
# TODO: 2FA
203204
info(f"Backup ID {backup_id} deleted by user {current_user.nickname} (ID: {current_user.id})")
204205
Backup.delete_by_id(backup_id)
206+
# TODO: Delete the actual archive
207+
# (Maybe schedule a task to purge deleted backups after some time to allow time for restore?)
208+
# Also add a confirmation dialog
205209
return redirect(url_for('AutobackupController.backup_index'))
206210

207211
@AutobackupController.route('/backup/<int:backup_id>/download')
@@ -277,6 +281,8 @@ def backup_status():
277281
statuses[tag].status.status = Status.Done
278282
statuses[tag].status.messages.append(current_message)
279283
if all([w.status.status == Status.Done for w in statuses.values()]):
284+
# TODO: This does not run after the first backup is done? Only fixed by a restart
285+
# Makes no sense since the dict is cleared in the finish_backup function
280286
info(f"Backup finished")
281287
finish_backup()
282288
case _:

constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
APP_VERSION = "1.1.0"
1+
APP_VERSION = "1.1.1"
22
BRANCH_ID = "CS"

static/js/backup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function statusMessage(status) {
167167
}
168168

169169
let updateIntervalId = 0;
170+
let finishedWikiCount = 0;
170171

171172
function updateStatus() {
172173
fetch('/backup/status').then(response => response.json()).then(data => {
@@ -201,7 +202,9 @@ function updateStatus() {
201202
case MessageType.ErrorFatal: messageStrings.push(`[${msg.tag}] Kritická chyba: ${msg.error_message}`); break;
202203
case MessageType.FinishSuccess:
203204
messageStrings.push(`[${msg.tag}] Záloha dokončena, zpracovávám data`);
204-
clearInterval(updateIntervalId);
205+
if(++finishedWikiCount === data.length) {
206+
clearInterval(updateIntervalId);
207+
}
205208
break;
206209
}
207210
})
@@ -222,6 +225,7 @@ function logMessage(message) {
222225
}
223226

224227
async function start_backup() {
228+
finishedWikiCount = 0;
225229
updateIntervalId = setInterval(updateStatus, 2000);
226230
$('#status-text').text('Záloha spuštěna');
227231
let response = await fetch('/backup/start')

0 commit comments

Comments
 (0)