mirror of
https://github.com/lorsanstand/Aether.git
synced 2026-06-19 12:05:16 +03:00
Edit get avatar
This commit is contained in:
@@ -13,6 +13,7 @@ class Settings(BaseSettings):
|
|||||||
BACKEND_PORT: int
|
BACKEND_PORT: int
|
||||||
WORKERS: int
|
WORKERS: int
|
||||||
FRONTEND_URL: str
|
FRONTEND_URL: str
|
||||||
|
BACKEND_URL: str
|
||||||
|
|
||||||
FIRST_SUPER_USER_EMAIL: str
|
FIRST_SUPER_USER_EMAIL: str
|
||||||
FIRST_SUPER_USER_PASS: str
|
FIRST_SUPER_USER_PASS: str
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from app.chats.router import router as chat_router
|
|||||||
from app.core.log_config import set_logging
|
from app.core.log_config import set_logging
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.services.messenger_service import PubSubMessenger
|
from app.services.messenger_service import PubSubMessenger
|
||||||
|
from app.utils.S3_client import s3_client
|
||||||
|
|
||||||
set_logging()
|
set_logging()
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -42,6 +43,19 @@ api_router.include_router(chat_router)
|
|||||||
async def test_health():
|
async def test_health():
|
||||||
return {"status": True}
|
return {"status": True}
|
||||||
|
|
||||||
|
@api_router.get("/files/{filename}")
|
||||||
|
async def get_file(filename: str):
|
||||||
|
file_data = await s3_client.download_file(filename)
|
||||||
|
|
||||||
|
content_type = "image/jpeg"
|
||||||
|
if filename.endswith(".png"):
|
||||||
|
content_type = "image/png"
|
||||||
|
|
||||||
|
# Возвращаем файл напрямую из памяти
|
||||||
|
return Response(
|
||||||
|
content=file_data,
|
||||||
|
media_type=content_type
|
||||||
|
)
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title=settings.COMPANY_NAME,
|
title=settings.COMPANY_NAME,
|
||||||
description="## Backend messenger aether",
|
description="## Backend messenger aether",
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class UserService:
|
|||||||
@classmethod
|
@classmethod
|
||||||
async def upload_avatar(cls, user: UserModel, avatar: UploadFile) -> User:
|
async def upload_avatar(cls, user: UserModel, avatar: UploadFile) -> User:
|
||||||
async with async_session_maker() as session:
|
async with async_session_maker() as session:
|
||||||
allowed_types = ["image/jpeg", "image/png", "image/gif"]
|
allowed_types = ["image/jpeg", "image/png"]
|
||||||
|
|
||||||
if not avatar.content_type in allowed_types:
|
if not avatar.content_type in allowed_types:
|
||||||
log.warning("Using not allowed type photo", extra={"user_id": user.id})
|
log.warning("Using not allowed type photo", extra={"user_id": user.id})
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class S3Client:
|
|||||||
log.error(f"Unexpected S3 error: {str(e)}", extra={"object_name": object_name})
|
log.error(f"Unexpected S3 error: {str(e)}", extra={"object_name": object_name})
|
||||||
raise HTTPException(status.HTTP_503_SERVICE_UNAVAILABLE, detail="Unexpected S3 error")
|
raise HTTPException(status.HTTP_503_SERVICE_UNAVAILABLE, detail="Unexpected S3 error")
|
||||||
|
|
||||||
return f"{self.endpoint_url}/{self.bucket_name}/{object_name}"
|
return f"{settings.BACKEND_URL}/files/{object_name}"
|
||||||
|
|
||||||
|
|
||||||
async def download_file(
|
async def download_file(
|
||||||
|
|||||||
Reference in New Issue
Block a user