formatted project by python-black

This commit is contained in:
2026-11-10 09:52:42 +03:00
parent 7cd02da51d
commit 9899ee4676
66 changed files with 2517 additions and 944 deletions
+39 -17
View File
@@ -12,41 +12,63 @@ from app.domain import attachments
from app.endpoints.dependencies import CurrentUser, DbSession, S3Storage, UploadCapacity
from app.schemas.attachment import Attachment
router = APIRouter(prefix='/api/v1', tags=['attachments'])
router = APIRouter(prefix="/api/v1", tags=["attachments"])
@router.post('/chats/{chat_id}/attachments', status_code=202)
@router.post("/chats/{chat_id}/attachments", status_code=202)
async def upload(
request: Request, chat_id: UUID, user: CurrentUser, session: DbSession,
storage: S3Storage, capacity: UploadCapacity,
request: Request,
chat_id: UUID,
user: CurrentUser,
session: DbSession,
storage: S3Storage,
capacity: UploadCapacity,
filename: Annotated[str, Query(min_length=1, max_length=255)],
) -> Attachment:
return await attachments.receive_attachment(
session, storage, user, chat_id, capacity=capacity, filename=filename,
content_type=request.headers.get('content-type', '').lower(),
declared_length=request.headers.get('content-length'), chunks=request.stream(),
session,
storage,
user,
chat_id,
capacity=capacity,
filename=filename,
content_type=request.headers.get("content-type", "").lower(),
declared_length=request.headers.get("content-length"),
chunks=request.stream(),
)
@router.get('/attachments/{attachment_id}')
async def metadata(attachment_id: UUID, user: CurrentUser, session: DbSession) -> Attachment:
@router.get("/attachments/{attachment_id}")
async def metadata(
attachment_id: UUID, user: CurrentUser, session: DbSession
) -> Attachment:
return await attachments.get_attachment(session, user, attachment_id)
@router.get('/attachments/{attachment_id}/content')
@router.get("/attachments/{attachment_id}/content")
async def content(
attachment_id: UUID, user: CurrentUser, session: DbSession, storage: S3Storage,
variant: Annotated[str, Query()] = 'original',
attachment_id: UUID,
user: CurrentUser,
session: DbSession,
storage: S3Storage,
variant: Annotated[str, Query()] = "original",
) -> StreamingResponse:
record, stream = await attachments.download_attachment(
session, storage, user, attachment_id, variant=variant,
session,
storage,
user,
attachment_id,
variant=variant,
)
return StreamingResponse(
stream, media_type=record.content_type,
stream,
media_type=record.content_type,
headers={
'Content-Length': str(record.size_bytes),
'Content-Disposition': "attachment; filename*=UTF-8''" + quote(record.filename, safe=''),
'X-Content-Type-Options': 'nosniff', 'Cache-Control': 'private, no-store',
"Content-Length": str(record.size_bytes),
"Content-Disposition": "attachment; filename*=UTF-8''"
+ quote(record.filename, safe=""),
"X-Content-Type-Options": "nosniff",
"Cache-Control": "private, no-store",
},
background=BackgroundTask(stream.aclose),
)
+7 -4
View File
@@ -3,18 +3,21 @@ from fastapi import APIRouter, Request
from app.domain import health
from app.schemas.base import Health
router = APIRouter(prefix='/health', tags=['health'])
router = APIRouter(prefix="/health", tags=["health"])
@router.get('/live')
@router.get("/live")
async def liveness() -> Health:
return health.liveness()
@router.get('/ready')
@router.get("/ready")
async def readiness(request: Request) -> Health:
state = request.app.state
return await health.readiness(
state.engine, state.redis, state.s3, state.lifecycle,
state.engine,
state.redis,
state.s3,
state.lifecycle,
state.settings.readiness_timeout_seconds,
)
+6 -2
View File
@@ -21,9 +21,13 @@ async def send_new_message(
idempotency_key: Annotated[str | None, Header(alias="Idempotency-Key")] = None,
) -> Message:
return await send_message_idempotent(
session, sender, chat_id, new_message,
session,
sender,
chat_id,
new_message,
validate_idempotency_key(idempotency_key),
settings.max_messages, settings.idempotency_ttl_seconds,
settings.max_messages,
settings.idempotency_ttl_seconds,
)