71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
from fastapi import APIRouter, UploadFile, status, Depends
|
|
|
|
from app.images.shemas import SImageUrl, Responses
|
|
from app.services import image_service
|
|
from app.dependencies import get_verificated_user
|
|
|
|
router = APIRouter(prefix="/images", tags=["Загрузка картинок"])
|
|
|
|
|
|
@router.post(
|
|
"/upload_avatar",
|
|
status_code=status.HTTP_200_OK,
|
|
response_model=SImageUrl,
|
|
responses={
|
|
status.HTTP_401_UNAUTHORIZED: {
|
|
"model": Responses.STokenMissingException,
|
|
"description": "Токен отсутствует"
|
|
},
|
|
status.HTTP_403_FORBIDDEN: {
|
|
"model": Responses.SNotAuthenticated,
|
|
"description": "Not authenticated"
|
|
},
|
|
status.HTTP_404_NOT_FOUND: {
|
|
"model": Responses.SUserNotFoundException,
|
|
"description": "Юзер не найден"
|
|
},
|
|
status.HTTP_409_CONFLICT: {
|
|
"model": Responses.SUserMustConfirmEmailException,
|
|
"description": "Сначала подтвердите почту"
|
|
},
|
|
status.HTTP_500_INTERNAL_SERVER_ERROR: {
|
|
"model": Responses.SBlackPhoenixException,
|
|
"description": "Внутренняя ошибка сервера"
|
|
},
|
|
},
|
|
)
|
|
async def upload_avatar(file: UploadFile, _=Depends(get_verificated_user)):
|
|
image_url = await image_service.upload_file_returning_str(file, "upload_avatar")
|
|
return {"image_url": image_url}
|
|
|
|
|
|
@router.post(
|
|
"/upload_image",
|
|
status_code=status.HTTP_200_OK,
|
|
response_model=SImageUrl,
|
|
responses={
|
|
status.HTTP_401_UNAUTHORIZED: {
|
|
"model": Responses.STokenMissingException,
|
|
"description": "Токен отсутствует"
|
|
},
|
|
status.HTTP_403_FORBIDDEN: {
|
|
"model": Responses.SNotAuthenticated,
|
|
"description": "Not authenticated"
|
|
},
|
|
status.HTTP_404_NOT_FOUND: {
|
|
"model": Responses.SUserNotFoundException,
|
|
"description": "Юзер не найден"
|
|
},
|
|
status.HTTP_409_CONFLICT: {
|
|
"model": Responses.SUserMustConfirmEmailException,
|
|
"description": "Сначала подтвердите почту"
|
|
},
|
|
status.HTTP_500_INTERNAL_SERVER_ERROR: {
|
|
"model": Responses.SBlackPhoenixException,
|
|
"description": "Внутренняя ошибка сервера"
|
|
},
|
|
},
|
|
)
|
|
async def upload_image(file: UploadFile, _=Depends(get_verificated_user)):
|
|
image_url = await image_service.upload_file_returning_str(file, "upload_image")
|
|
return {"image_url": image_url}
|