Refactors Services and Initial Test Implementation
This commit is contained in:
0
storage_service/utils/file/__init__.py
Normal file
0
storage_service/utils/file/__init__.py
Normal file
9
storage_service/utils/file/file_hash_generator.py
Normal file
9
storage_service/utils/file/file_hash_generator.py
Normal 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}"
|
||||
1
storage_service/utils/file/validators/__init__.py
Normal file
1
storage_service/utils/file/validators/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .image_handler import image_validator
|
||||
20
storage_service/utils/file/validators/image_handler.py
Normal file
20
storage_service/utils/file/validators/image_handler.py
Normal 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
|
||||
Reference in New Issue
Block a user