From 7e4883dcffa3c555951260af6e264ab46f94983c Mon Sep 17 00:00:00 2001 From: CREATIVE_tg1 <1+creative_tg1@noreply.localhost> Date: Wed, 27 May 2026 14:58:02 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=83?= =?UTF-8?q?=20FastAPI=20Integration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastAPI-Integration.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/FastAPI-Integration.md b/FastAPI-Integration.md index 5b8d187..1e60433 100644 --- a/FastAPI-Integration.md +++ b/FastAPI-Integration.md @@ -16,20 +16,20 @@ from yt_shorts_downloader.exceptions import YtShortsDownloaderError app = FastAPI() -+@app.get('/download') -+def download_short(url: str) -> Response: -+ try: -+ video = download(url, 'cookies.txt') -+ except YtShortsDownloaderError as exc: -+ raise HTTPException(status_code=400, detail=str(exc)) from exc -+ -+ return Response( -+ content=video.content, -+ media_type=video.media_type, -+ headers={ -+ 'Content-Disposition': f'attachment; filename="{video.filename}"', -+ }, -+ ) +@app.get('/download') +def download_short(url: str) -> Response: + try: + video = download(url, 'cookies.txt') + except YtShortsDownloaderError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc + + return Response( + content=video.content, + media_type=video.media_type, + headers={ + 'Content-Disposition': f'attachment; filename="{video.filename}"', + }, + ) ``` ## Что важно учитывать @@ -43,5 +43,5 @@ app = FastAPI() - валидируйте входной URL на уровне API-контракта - добавьте rate limiting на endpoint скачивания -- логируйте текст `str(exc)` для диагностики ошибок авторизации и yt-dlp -- храните cookie-файл вне публичных директорий и вне docker image layer history, если это возможно +- логируйте `str(exc)` для диагностики ошибок авторизации и yt-dlp +- храните cookie-файл вне публичных директорий и вне истории docker image layers, если это возможно