Implements Better Abstraction on Top of StorageService and File Handlers

Adds Expiration Time to Config

Reformats Project
This commit is contained in:
2023-08-10 01:54:17 -03:00
parent 0b320a3222
commit 2bd7ae10b9
12 changed files with 125 additions and 66 deletions

View File

@@ -1,11 +1,11 @@
from resize_image_service.depends.depend_queue import dependency_queue
from resize_image_service.depends.depend_s3_service import (
dependency_s3_service,
dependency_storage_service,
)
from resize_image_service.service.s3_service import S3Service
from resize_image_service.service.storage_service import StorageService
from resize_image_service.utils.enums.file_type import FileType
from resize_image_service.utils.file_name_hash import file_name_hash
from resize_image_service.worker.s3_image_worker import s3_image_worker
from resize_image_service.worker.storage_file_worker import storage_file_worker
from fastapi import Body, Depends, Form
from fastapi_utils.cbv import cbv
@@ -20,27 +20,29 @@ s3_router = InferringRouter()
@cbv(s3_router)
class S3Controller:
queue: Queue = Depends(dependency_queue, use_cache=True)
s3_service: S3Service = Depends(dependency_s3_service, use_cache=True)
storage_service: StorageService = Depends(dependency_storage_service, use_cache=True)
@s3_router.get("/new_file_url/", status_code=200)
def new_file_url(
self,
username: Annotated[str, Form()],
file_postfix: Annotated[str, Form()],
file_type: Annotated[FileType, Form()],
username: Annotated[str, Body(embed=True)],
file_postfix: Annotated[str, Body(embed=True)],
file_type: Annotated[FileType, Body(embed=True)],
) -> dict[str, str]:
return self.s3_service.get_temp_upload_link(
return self.storage_service.get_temp_upload_link(
file_name_hash(username, file_postfix), file_type
)
@s3_router.get("/file_url/", status_code=200)
def file_url(
self, username: Annotated[str, Form()], file_postfix: Annotated[str, Form()]
self,
username: Annotated[str, Body(embed=True)],
file_postfix: Annotated[str, Body(embed=True)],
) -> dict[str, str]:
return self.s3_service.get_temp_read_link(
return self.storage_service.get_temp_read_link(
file_name_hash(username, file_postfix)
)
@s3_router.post("/process_image/", status_code=200)
def process_image(self, string_url: Annotated[str, Body(embed=True)]):
self.queue.enqueue(s3_image_worker, string_url)
@s3_router.post("/process_file/", status_code=200)
def process_file(self, string_url: Annotated[str, Body(embed=True)]):
self.queue.enqueue(storage_file_worker, string_url)