From 4a37e46ab9525aa217733a081e1bfb16374497a9 Mon Sep 17 00:00:00 2001 From: Dantenerosas Date: Mon, 25 Sep 2023 17:43:24 +0300 Subject: [PATCH] up --- src/web/main.py | 20 ++++++++++++++++++-- src/web/schemes/submit.py | 1 + src/web/templates/index.html | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/web/main.py b/src/web/main.py index 01a591e..2f498d0 100644 --- a/src/web/main.py +++ b/src/web/main.py @@ -28,6 +28,23 @@ app.add_middleware( ) +''' + await self.app(scope, receive, send) + File "/home/admin/video_downloader_service/.venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app + response = await func(request) + File "/home/admin/video_downloader_service/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 273, in app + raw_response = await run_endpoint_function( + File "/home/admin/video_downloader_service/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 190, in run_endpoint_function + return await dependant.call(**values) + File "/home/admin/video_downloader_service/src/web/main.py", line 81, in get_url_for_download_video + task_done = await is_task_already_done_or_exist(red, data.link) + File "/home/admin/video_downloader_service/src/web/main.py", line 34, in is_task_already_done_or_exist + tasks = [ + File "/home/admin/video_downloader_service/src/web/main.py", line 36, in + if literal_eval(message.decode('utf-8'))["link"] == link +TypeError: string indices must be integers +''' + async def is_task_already_done_or_exist(redis: RedisClient, link: str): # TODO: добавить real_link? пример - https://yandex.ru/video/preview/398425296752711999 будет грузить https://youtu.be/EjhRS4HUSJc messages = await redis.get_task_done_queue() @@ -172,5 +189,4 @@ async def download_video(request: Request, link: str): print(ex) -if __name__ == '__main__': - uvicorn.run("src.web.main:app", host="0.0.0.0", log_level="info") +uvicorn.run("src.web.main:app", host="0.0.0.0", log_level="info") diff --git a/src/web/schemes/submit.py b/src/web/schemes/submit.py index 1ee470b..482453a 100644 --- a/src/web/schemes/submit.py +++ b/src/web/schemes/submit.py @@ -39,6 +39,7 @@ class MergeOutputFormatEnum(Enum): @dataclass class SubmitIn: + #TODO: дефолтный значения link: str = Form(...) video_format: VideoFormatEnum = Form(...) audio_format: AudioFormatEnum = Form(...) diff --git a/src/web/templates/index.html b/src/web/templates/index.html index 32a7ef3..8bea704 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -92,10 +92,11 @@ document.forms.download.querySelector('.submit-spinner').classList.remove('submit-spinner_hide'); const link = document.getElementById("link").value const xhr2 = new XMLHttpRequest(); + // TODO: скорректировать ссылку, она должна быть относительной xhr2.open('GET', 'http://0.0.0.0:8000/check/?link=' + link); xhr2.responseType = 'json'; xhr2.onload = function() { - + // TODO: добавить обработку исключений и всех возможных кодов в ответе if (xhr2.status !== 200) { if ('response' in xhr2 && xhr2.response !== null) { console.log(xhr2.response)