mirror of
https://github.com/flibusta-apps/telegram_files_server.git
synced 2025-12-06 12:35:39 +01:00
Update uploading/downloading
This commit is contained in:
@@ -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: {}})
|
||||
|
||||
Reference in New Issue
Block a user