Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/astroidapi/attachment_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import astroidapi.errors as errors
import astroidapi.surrealdb_handler as surrealdb_handler
import pathlib
import random
import pathlib
import string
import secrets

async def download_attachment(attachment_url, registeredPlatforms):
try:
Expand All @@ -20,7 +20,7 @@ async def download_attachment(attachment_url, registeredPlatforms):
raise errors.AttachmentProcessError.AttachmentDownloadError.AttachmentTooLarge("Attachment is too large. Maximum size is 50MB.")
print(f"Downloading attachment from {attachment_url}. Size: {int(content_length) / 1024 }KB")
id_chars = string.ascii_lowercase + string.digits
attachment_id = "".join(random.choices(id_chars, k=16))
attachment_id = "".join(secrets.SystemRandom().choices(id_chars, k=16))
attachment_name = attachment_url.split('/')[-1]
attachment_type = attachment_name.split('.')[-1]
if "?" in attachment_type:
Expand Down Expand Up @@ -90,4 +90,4 @@ async def force_clear_temporary_attachments():
await surrealdb_handler.AttachmentProcessor.delete_attachment(file.name.split('.')[0])
file.unlink()
except Exception as e:
raise errors.AttachmentProcessError.AttachmentClearError.DeletionError(f"Error deleting temporary attachments. Error: {e}")
raise errors.AttachmentProcessError.AttachmentClearError.DeletionError(f"Error deleting temporary attachments. Error: {e}")
Loading