Reformats Code

This commit is contained in:
2024-05-21 19:25:44 -03:00
parent 0acf167d12
commit a1077e812f
9 changed files with 26 additions and 26 deletions

View File

@@ -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()

View File

@@ -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):

View File

@@ -1,2 +1,2 @@
from .storage_service import StorageService
from .amazon_s3_service import AmazonS3Service
from .storage_service import StorageService

View File

@@ -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__)

View File

@@ -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"

View File

@@ -12,4 +12,4 @@ async def http_exception_handler(request: Request, exc: HTTPException):
"status_code": exc.status_code,
}
},
)
)

View File

@@ -17,4 +17,4 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
"status_code": status_code,
}
},
)
)

View File

@@ -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)

View File

@@ -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)