Refactors Services and Initial Test Implementation

This commit is contained in:
2024-05-21 03:35:24 -03:00
parent b93faf11b3
commit 7eb4d5b64d
21 changed files with 336 additions and 34 deletions

View File

View File

@@ -0,0 +1,9 @@
import base64
from hashlib import md5
def generate_file_hash(file_key: str, file_postfix: str) -> str:
hashed_file_key = md5(file_key.encode("utf-8")).digest()
hashed_file_key = base64.b64encode(hashed_file_key).decode()
return f"{hashed_file_key}_{file_postfix}"

View File

@@ -0,0 +1 @@
from .image_handler import image_validator

View File

@@ -0,0 +1,20 @@
from PIL import Image
import io
def image_validator(file_bytes: io.BytesIO) -> io.BytesIO:
img = Image.open(file_bytes)
img.thumbnail((180, 180))
data = list(img.getdata())
image_without_exif = Image.new(img.mode, img.size)
image_without_exif.putdata(data)
new_byte_img = io.BytesIO()
img.save(new_byte_img, format="PNG")
new_byte_img.seek(0)
return new_byte_img