fix(Filename):

Fix filename (Obfuscate during save)
This commit is contained in:
Devoalda 2023-10-29 16:40:17 +08:00
parent 87d0c6d64f
commit de235d5ec2
1 changed files with 6 additions and 2 deletions

View File

@ -72,18 +72,22 @@ class ManageItemsView(APIView):
# Encrypted Data Buffer # Encrypted Data Buffer
encrypted_data = b"" encrypted_data = b""
# Encrypt the filename
encrypted_filename = cipher_suite.encrypt(filename.encode())
# Reopen the file to encrypt it with the encryption key and Fernet algorithm # Reopen the file to encrypt it with the encryption key and Fernet algorithm
with open(save_path, 'rb') as source_file: with open(save_path, 'rb') as source_file:
for chunk in source_file: for chunk in source_file:
encrypted_chunk = cipher_suite.encrypt(chunk) encrypted_chunk = cipher_suite.encrypt(chunk)
encrypted_data += encrypted_chunk encrypted_data += encrypted_chunk
# New save path
save_path = os.path.join(settings.MEDIA_ROOT, str(encrypted_filename))
# Overwrite the file with the encrypted data # Overwrite the file with the encrypted data
with open(save_path, 'wb') as destination: with open(save_path, 'wb') as destination:
destination.write(encrypted_data) destination.write(encrypted_data)
# Encrypt the filename
encrypted_filename = cipher_suite.encrypt(filename.encode())
# Store the file path and encryption key in the cache with the provided TTL # Store the file path and encryption key in the cache with the provided TTL
cache.set(key, cache.set(key,