Implemented safe save feature so that existing file is not replaced, possibly leading to loss of flagging information.

This commit is contained in:
2024-11-15 16:56:11 +01:00
parent d89d6b13c9
commit 2dc1b98ec8

View File

@ -31,9 +31,14 @@ def save_file(name, content):
content_type, content_string = content.split(',')
decoded = base64.b64decode(content_string)
file_path = os.path.join(UPLOAD_DIRECTORY, name)
with open(file_path, "wb") as f:
f.write(decoded)
return file_path
if not os.path.exists(file_path):
with open(file_path, "wb") as f:
f.write(decoded)
print(f"File saved successfully at {file_path}")
return file_path
else:
print(f'File already exists at {file_path}.\nTo maintain the integrity of the existing file, it will not be overwritten.')
return file_path
def filter_flags_by_label(flags_dict, label):
"""