Reformats Code
This commit is contained in:
@@ -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.config.config_allowed_origins import get_allowed_origins
|
||||||
from storage_service.controller.health_checker_controller import health_router
|
from storage_service.controller.health_checker_controller import health_router
|
||||||
from storage_service.controller.storage_controller import s3_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 import FastAPI, HTTPException
|
||||||
|
from fastapi.exceptions import RequestValidationError
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from starlette.responses import JSONResponse
|
||||||
from storage_service.utils.exception_handler import http_exception_handler, validation_exception_handler
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|||||||
@@ -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.model.storage.signed_url_response import SignedUrlResponse
|
||||||
from storage_service.service.storage.storage_service import StorageService
|
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.utils.file.file_hash_generator import generate_file_hash
|
||||||
from storage_service.worker.storage_file_worker import storage_file_worker
|
from storage_service.worker.storage_file_worker import storage_file_worker
|
||||||
|
|
||||||
@@ -49,7 +51,9 @@ class StorageController:
|
|||||||
|
|
||||||
@s3_router.delete("/file", status_code=204)
|
@s3_router.delete("/file", status_code=204)
|
||||||
def delete_file(self, file_key: str, file_postfix: str):
|
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)
|
@s3_router.post("/file/process", status_code=200)
|
||||||
def process_file(self, process_file_request: ProcessFileRequest):
|
def process_file(self, process_file_request: ProcessFileRequest):
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
from .storage_service import StorageService
|
|
||||||
from .amazon_s3_service import AmazonS3Service
|
from .amazon_s3_service import AmazonS3Service
|
||||||
|
from .storage_service import StorageService
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from storage_service.depends.depend_virus_checker_service import (
|
from storage_service.depends.depend_virus_checker_service import (
|
||||||
dependency_virus_checker_service,
|
dependency_virus_checker_service,
|
||||||
)
|
)
|
||||||
@@ -15,7 +13,7 @@ from storage_service.utils.enums.file_type import FileType
|
|||||||
from botocore.client import BaseClient
|
from botocore.client import BaseClient
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
from storage_service.utils.file.validators import image_validator
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from storage_service.utils.file.validators import image_validator
|
|
||||||
|
|
||||||
|
|
||||||
class FileType(Enum):
|
class FileType(Enum):
|
||||||
PNG = "png"
|
PNG = "png"
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ async def http_exception_handler(request: Request, exc: HTTPException):
|
|||||||
"status_code": exc.status_code,
|
"status_code": exc.status_code,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
|
|||||||
"status_code": status_code,
|
"status_code": status_code,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,4 @@ from fastapi import HTTPException, status
|
|||||||
|
|
||||||
class FileNotFoundException(HTTPException):
|
class FileNotFoundException(HTTPException):
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__(
|
super().__init__(status.HTTP_404_NOT_FOUND, detail=message)
|
||||||
status.HTTP_404_NOT_FOUND, detail=message
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from storage_service.depends.depend_s3_service import (
|
from storage_service.depends.depend_s3_service import (
|
||||||
dependency_storage_service,
|
dependency_storage_service,
|
||||||
)
|
)
|
||||||
from storage_service.utils.file.file_hash_generator import generate_file_hash
|
from storage_service.utils.file.file_hash_generator import generate_file_hash
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -16,15 +15,15 @@ def storage_file_worker(username: str, file_postfix: str) -> None:
|
|||||||
try:
|
try:
|
||||||
stats = storage_service.process_file(file_name)
|
stats = storage_service.process_file(file_name)
|
||||||
|
|
||||||
|
previous_size_kb = stats["previous_size"] / 1_000
|
||||||
|
current_size_kb = stats["current_size"] / 1_000
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"File processed: {file_name} - "
|
f"File processed: {file_name} - "
|
||||||
f"Previous Size: {stats["previous_size"]/1_000}kb - "
|
f"Previous Size: {previous_size_kb}kb - "
|
||||||
f"New Size: {stats["current_size"]/1_000}kb"
|
f"New Size: {current_size_kb}kb"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(
|
print(f"Error processing file: {e}." f" Deleting file: {file_name}.")
|
||||||
f"Error processing file: {e}."
|
|
||||||
f" Deleting file: {file_name}."
|
|
||||||
)
|
|
||||||
|
|
||||||
storage_service.delete_file(file_name)
|
storage_service.delete_file(file_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user