Skip to content

Commit

Permalink
Update image.py
Browse files Browse the repository at this point in the history
  • Loading branch information
iskomir authored Feb 4, 2024
1 parent 495af3e commit 5cb741c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions calendar_backend/methods/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
settings = get_settings()


async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo:
"""
Uploads the lecturer's photo to the database
"""
async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo:
"""
Uploads the lecturer's photo to the database
"""
lecturer = Lecturer.get(lecturer_id, session=session)
random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32))
ext = file.filename.split('.')[-1]
Expand All @@ -46,10 +46,10 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload
return photo


def process_image(image_bytes: bytes) -> None:
"""
Checks the integrity of the image
"""
def process_image(image_bytes: bytes) -> None:
"""
Checks the integrity of the image
"""
with Image.open(BytesIO(image_bytes)) as image:
try:
image.verify()
Expand All @@ -60,18 +60,18 @@ def process_image(image_bytes: bytes) -> None:
thread_pool = ThreadPoolExecutor()


async def async_image_process(image_bytes: bytes) -> None:
"""
Asynchronous image processing
"""
async def async_image_process(image_bytes: bytes) -> None:
"""
Asynchronous image processing
"""
loop = asyncio.get_event_loop()
await loop.run_in_executor(thread_pool, partial(process_image, image_bytes))


def get_photo_webpath(file_path: str):
"""
Returns the webpath of the file
"""
def get_photo_webpath(file_path: str):
"""
Returns the webpath of the file
"""
file_path = file_path.removeprefix('/')
root_path = settings.ROOT_PATH.removesuffix('/')
return f"{root_path}/static/photo/lecturer/{file_path}"

0 comments on commit 5cb741c

Please sign in to comment.