diff --git a/storage_service/controller/__init__.py b/storage_service/controller/__init__.py index 67a96b3..26c566d 100644 --- a/storage_service/controller/__init__.py +++ b/storage_service/controller/__init__.py @@ -1,14 +1,15 @@ -from fastapi.exceptions import RequestValidationError -from starlette.responses import JSONResponse - from storage_service.config.config_allowed_origins import get_allowed_origins from storage_service.controller.health_checker_controller import health_router from storage_service.controller.storage_controller import s3_router +from storage_service.utils.exception_handler import ( + http_exception_handler, + validation_exception_handler, +) from fastapi import FastAPI, HTTPException +from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware - -from storage_service.utils.exception_handler import http_exception_handler, validation_exception_handler +from starlette.responses import JSONResponse app = FastAPI() diff --git a/storage_service/controller/storage_controller.py b/storage_service/controller/storage_controller.py index 86ecbe5..367abf5 100644 --- a/storage_service/controller/storage_controller.py +++ b/storage_service/controller/storage_controller.py @@ -10,7 +10,9 @@ from storage_service.model.storage.process_file_request import ( ) from storage_service.model.storage.signed_url_response import SignedUrlResponse from storage_service.service.storage.storage_service import StorageService -from storage_service.utils.exceptions.file_not_found_exception import FileNotFoundException +from storage_service.utils.exceptions.file_not_found_exception import ( + FileNotFoundException, +) from storage_service.utils.file.file_hash_generator import generate_file_hash from storage_service.worker.storage_file_worker import storage_file_worker @@ -49,7 +51,9 @@ class StorageController: @s3_router.delete("/file", status_code=204) def delete_file(self, file_key: str, file_postfix: str): - return self.storage_service.delete_file(generate_file_hash(file_key, file_postfix)) + return self.storage_service.delete_file( + generate_file_hash(file_key, file_postfix) + ) @s3_router.post("/file/process", status_code=200) def process_file(self, process_file_request: ProcessFileRequest): diff --git a/storage_service/service/storage/__init__.py b/storage_service/service/storage/__init__.py index 9433f92..55a97ea 100644 --- a/storage_service/service/storage/__init__.py +++ b/storage_service/service/storage/__init__.py @@ -1,2 +1,2 @@ -from .storage_service import StorageService from .amazon_s3_service import AmazonS3Service +from .storage_service import StorageService diff --git a/storage_service/service/storage/amazon_s3_service.py b/storage_service/service/storage/amazon_s3_service.py index 41a6a32..c9331b2 100644 --- a/storage_service/service/storage/amazon_s3_service.py +++ b/storage_service/service/storage/amazon_s3_service.py @@ -1,7 +1,5 @@ from __future__ import annotations -import logging - from storage_service.depends.depend_virus_checker_service import ( dependency_virus_checker_service, ) @@ -15,7 +13,7 @@ from storage_service.utils.enums.file_type import FileType from botocore.client import BaseClient import io - +import logging logger = logging.getLogger(__name__) diff --git a/storage_service/utils/enums/file_type.py b/storage_service/utils/enums/file_type.py index 149e4c3..7c55e1b 100644 --- a/storage_service/utils/enums/file_type.py +++ b/storage_service/utils/enums/file_type.py @@ -1,9 +1,9 @@ +from storage_service.utils.file.validators import image_validator + from enum import Enum from io import BytesIO from typing import Callable -from storage_service.utils.file.validators import image_validator - class FileType(Enum): PNG = "png" diff --git a/storage_service/utils/exception_handler/http_exception_handler.py b/storage_service/utils/exception_handler/http_exception_handler.py index 2df36d1..e4ffee9 100644 --- a/storage_service/utils/exception_handler/http_exception_handler.py +++ b/storage_service/utils/exception_handler/http_exception_handler.py @@ -12,4 +12,4 @@ async def http_exception_handler(request: Request, exc: HTTPException): "status_code": exc.status_code, } }, - ) \ No newline at end of file + ) diff --git a/storage_service/utils/exception_handler/validation_exception_handler.py b/storage_service/utils/exception_handler/validation_exception_handler.py index 9cc47d7..19bb9a9 100644 --- a/storage_service/utils/exception_handler/validation_exception_handler.py +++ b/storage_service/utils/exception_handler/validation_exception_handler.py @@ -17,4 +17,4 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE "status_code": status_code, } }, - ) \ No newline at end of file + ) diff --git a/storage_service/utils/exceptions/file_not_found_exception.py b/storage_service/utils/exceptions/file_not_found_exception.py index f61a934..d4df535 100644 --- a/storage_service/utils/exceptions/file_not_found_exception.py +++ b/storage_service/utils/exceptions/file_not_found_exception.py @@ -3,6 +3,4 @@ from fastapi import HTTPException, status class FileNotFoundException(HTTPException): def __init__(self, message: str): - super().__init__( - status.HTTP_404_NOT_FOUND, detail=message - ) + super().__init__(status.HTTP_404_NOT_FOUND, detail=message) diff --git a/storage_service/worker/storage_file_worker.py b/storage_service/worker/storage_file_worker.py index afc6752..d9b5efd 100644 --- a/storage_service/worker/storage_file_worker.py +++ b/storage_service/worker/storage_file_worker.py @@ -1,10 +1,9 @@ -import logging - from storage_service.depends.depend_s3_service import ( dependency_storage_service, ) from storage_service.utils.file.file_hash_generator import generate_file_hash +import logging logger = logging.getLogger(__name__) @@ -16,15 +15,15 @@ def storage_file_worker(username: str, file_postfix: str) -> None: try: stats = storage_service.process_file(file_name) + previous_size_kb = stats["previous_size"] / 1_000 + current_size_kb = stats["current_size"] / 1_000 + print( f"File processed: {file_name} - " - f"Previous Size: {stats["previous_size"]/1_000}kb - " - f"New Size: {stats["current_size"]/1_000}kb" + f"Previous Size: {previous_size_kb}kb - " + f"New Size: {current_size_kb}kb" ) except Exception as e: - print( - f"Error processing file: {e}." - f" Deleting file: {file_name}." - ) + print(f"Error processing file: {e}." f" Deleting file: {file_name}.") storage_service.delete_file(file_name)