fix download

This commit is contained in:
jxxghp
2023-07-08 16:30:45 +08:00
parent b6d957c7d9
commit 5ceaf94169
8 changed files with 34 additions and 7 deletions

View File

@ -6,9 +6,11 @@ from app import schemas
from app.chain.douban import DoubanChain
from app.chain.download import DownloadChain
from app.chain.media import MediaChain
from app.core.context import MediaInfo
from app.core.context import MediaInfo, Context, TorrentInfo
from app.core.metainfo import MetaInfo
from app.core.security import verify_token
from app.db.models.user import User
from app.db.userauth import get_current_active_superuser
from app.schemas import NotExistMediaInfo, MediaType
router = APIRouter()
@ -23,6 +25,25 @@ async def read_downloading(
return DownloadChain().downloading()
@router.post("/", summary="添加下载", response_model=schemas.Response)
async def add_downloading(
media_in: schemas.MediaInfo,
torrent_in: schemas.TorrentInfo,
current_user: User = Depends(get_current_active_superuser)) -> Any:
"""
添加下载任务
"""
context = Context(
meta_info=MetaInfo(title=torrent_in.title, subtitle=torrent_in.description),
media_info=MediaInfo().from_dict(media_in.dict()),
torrent_info=TorrentInfo(**torrent_in.dict())
)
did = DownloadChain().download_single(context=context, userid=current_user.name)
return schemas.Response(success=True if did else False, data={
"download_id": did
})
@router.post("/notexists", summary="查询缺失媒体信息", response_model=List[NotExistMediaInfo])
async def exists(media_in: schemas.MediaInfo,
_: schemas.TokenPayload = Depends(verify_token)) -> Any: