minor fixes
This commit is contained in:
parent
43a4874d4b
commit
d3200f0bf2
@ -11,7 +11,7 @@ from starlette.responses import JSONResponse, FileResponse, StreamingResponse
|
|||||||
from starlette.templating import Jinja2Templates
|
from starlette.templating import Jinja2Templates
|
||||||
|
|
||||||
from src.core.redis_client import RedisClient
|
from src.core.redis_client import RedisClient
|
||||||
from src.web.schemes.submit import SubmitIn
|
from src.web.schemes.submit import SubmitIn, CheckIn
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="video_downloader", openapi_url=f"/api/v1/openapi.json"
|
title="video_downloader", openapi_url=f"/api/v1/openapi.json"
|
||||||
@ -59,6 +59,7 @@ queue_name -> {
|
|||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
async def is_task_already_done_or_exist(redis: RedisClient, link: str):
|
async def is_task_already_done_or_exist(redis: RedisClient, link: str):
|
||||||
messages = await redis.get_task_done_queue()
|
messages = await redis.get_task_done_queue()
|
||||||
temp = [json.loads(msg) for msg in messages]
|
temp = [json.loads(msg) for msg in messages]
|
||||||
@ -91,7 +92,7 @@ async def index(request: Request):
|
|||||||
return templates.TemplateResponse("index.html", {"request": request})
|
return templates.TemplateResponse("index.html", {"request": request})
|
||||||
|
|
||||||
|
|
||||||
@app.post('/submit/')
|
@app.post('/submit')
|
||||||
async def get_url_for_download_video(request: Request, data: SubmitIn = Depends()):
|
async def get_url_for_download_video(request: Request, data: SubmitIn = Depends()):
|
||||||
red = RedisClient()
|
red = RedisClient()
|
||||||
task_done = await is_task_already_done_or_exist(red, data.link)
|
task_done = await is_task_already_done_or_exist(red, data.link)
|
||||||
@ -148,19 +149,20 @@ async def download_video(file_path):
|
|||||||
|
|
||||||
|
|
||||||
@app.post('/check/', response_class=FileResponse, status_code=200)
|
@app.post('/check/', response_class=FileResponse, status_code=200)
|
||||||
async def download_video(request: Request, link: str):
|
async def download_video(data: CheckIn, request: Request):
|
||||||
try:
|
try:
|
||||||
red = RedisClient()
|
red = RedisClient()
|
||||||
|
|
||||||
messages_task_done = await red.get_task_done_queue()
|
messages_task_done = await red.get_task_done_queue()
|
||||||
messages_tasks = await red.get_tasks()
|
messages_tasks = await red.get_tasks()
|
||||||
|
|
||||||
tasks_done = [
|
tasks_done = [
|
||||||
literal_eval(message.decode('utf-8')) for message in messages_task_done
|
literal_eval(message.decode('utf-8')) for message in messages_task_done
|
||||||
if literal_eval(message.decode('utf-8'))["link"] == link
|
if literal_eval(message.decode('utf-8'))["link"] == data.link
|
||||||
]
|
]
|
||||||
tasks = [
|
tasks = [
|
||||||
literal_eval(message.decode('utf-8')) for message in messages_tasks
|
literal_eval(message.decode('utf-8')) for message in messages_tasks
|
||||||
if literal_eval(message.decode('utf-8'))["link"] == link
|
if literal_eval(message.decode('utf-8'))["link"] == data.link
|
||||||
]
|
]
|
||||||
|
|
||||||
error_tasks = [
|
error_tasks = [
|
||||||
|
@ -2,7 +2,7 @@ from dataclasses import dataclass
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
'''
|
'''
|
||||||
vext: Video Extension (mp4 > mov > webm > flv > other). If --prefer-free-formats is used, webm is preferred.
|
vext: Video Extension (mp4 > mov > webm > flv > other). If --prefer-free-formats is used, webm is preferred.
|
||||||
@ -44,3 +44,6 @@ class SubmitIn:
|
|||||||
audio_format: AudioFormatEnum = Form(default=AudioFormatEnum.format_m4a)
|
audio_format: AudioFormatEnum = Form(default=AudioFormatEnum.format_m4a)
|
||||||
merge_output_format: MergeOutputFormatEnum = Form(default=MergeOutputFormatEnum.format_mp4)
|
merge_output_format: MergeOutputFormatEnum = Form(default=MergeOutputFormatEnum.format_mp4)
|
||||||
|
|
||||||
|
|
||||||
|
class CheckIn(BaseModel):
|
||||||
|
link: str
|
||||||
|
@ -93,8 +93,10 @@
|
|||||||
const link = document.getElementById("link").value
|
const link = document.getElementById("link").value
|
||||||
const xhr2 = new XMLHttpRequest();
|
const xhr2 = new XMLHttpRequest();
|
||||||
// TODO: скорректировать ссылку, она должна быть относительной
|
// TODO: скорректировать ссылку, она должна быть относительной
|
||||||
xhr2.open('POST', 'http://'+document.location.host+'/check');
|
xhr2.open('POST', 'http://'+document.location.host+'/check/');
|
||||||
xhr2.responseType = 'json';
|
xhr2.responseType = 'json';
|
||||||
|
xhr2.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
|
||||||
xhr2.onload = function() {
|
xhr2.onload = function() {
|
||||||
// TODO: добавить обработку исключений и всех возможных кодов в ответе
|
// TODO: добавить обработку исключений и всех возможных кодов в ответе
|
||||||
if (xhr2.status !== 200) {
|
if (xhr2.status !== 200) {
|
||||||
@ -112,9 +114,10 @@
|
|||||||
document.forms.download.querySelector('.submit-spinner').classList.add('submit-spinner_hide');
|
document.forms.download.querySelector('.submit-spinner').classList.add('submit-spinner_hide');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
body = {};
|
var params = {
|
||||||
body.link = link;
|
"link":link,
|
||||||
xhr2.send(body)
|
};
|
||||||
|
setTimeout(function() { xhr2.send(JSON.stringify(params));}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user