Update uploading/downloading

This commit is contained in:
2022-02-07 10:45:48 +03:00
parent 67fc4e2e3e
commit 861b197981
7 changed files with 190 additions and 665 deletions

View File

@@ -1,15 +1,7 @@
from typing import Optional
from fastapi import (
File,
UploadFile,
Depends,
Form,
APIRouter,
HTTPException,
Response,
status,
)
from fastapi import File, UploadFile, Depends, Form, APIRouter, HTTPException, status
from fastapi.responses import StreamingResponse
from app.depends import check_token
from app.models import UploadedFile as UploadedFileDB
@@ -54,16 +46,6 @@ async def upload_file(file: UploadFile = File({}), caption: Optional[str] = Form
return await FileUploader.upload(file, caption=caption)
@router.get("/download_by_file_id/{file_id}")
async def download_by_file_id(file_id: str):
data = await FileDownloader.download_by_file_id(file_id)
if data is None:
raise HTTPException(status.HTTP_400_BAD_REQUEST)
return Response(data.read())
@router.get("/download_by_message/{chat_id}/{message_id}")
async def download_by_message(chat_id: str, message_id: int):
data = await FileDownloader.download_by_message_id(message_id)
@@ -71,7 +53,7 @@ async def download_by_message(chat_id: str, message_id: int):
if data is None:
raise HTTPException(status.HTTP_400_BAD_REQUEST)
return Response(data.read())
return StreamingResponse(data)
@router.delete("/{file_id}", response_model=UploadedFile, responses={400: {}})