From 5a5edfb2a3e2b8ab65c8eab70e2be5b1832503ee Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 2 Jul 2023 15:48:18 +0800 Subject: [PATCH] downloading api --- app/api/apiv1.py | 3 ++- app/api/endpoints/download.py | 18 ++++++++++++++++++ app/chain/download.py | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/api/endpoints/download.py diff --git a/app/api/apiv1.py b/app/api/apiv1.py index c7ba7ebc..412b1864 100644 --- a/app/api/apiv1.py +++ b/app/api/apiv1.py @@ -1,7 +1,7 @@ from fastapi import APIRouter from app.api.endpoints import login, user, site, message, webhook, subscribe, \ - media, douban, search, plugin, tmdb, history, system + media, douban, search, plugin, tmdb, history, system, download api_router = APIRouter() api_router.include_router(login.router, tags=["login"]) @@ -17,3 +17,4 @@ api_router.include_router(tmdb.router, prefix="/tmdb", tags=["tmdb"]) api_router.include_router(history.router, prefix="/history", tags=["history"]) api_router.include_router(system.router, prefix="/system", tags=["system"]) api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"]) +api_router.include_router(download.router, prefix="/download", tags=["download"]) diff --git a/app/api/endpoints/download.py b/app/api/endpoints/download.py new file mode 100644 index 00000000..12eaff3c --- /dev/null +++ b/app/api/endpoints/download.py @@ -0,0 +1,18 @@ +from typing import Any, List + +from fastapi import APIRouter, Depends + +from app import schemas +from app.chain.download import DownloadChain +from app.core.security import verify_token + +router = APIRouter() + + +@router.get("/", summary="正在下载", response_model=List[schemas.DownloadingTorrent]) +async def read_subscribes( + _: schemas.TokenPayload = Depends(verify_token)) -> Any: + """ + 查询正在下载的任务 + """ + return DownloadChain().downloading() diff --git a/app/chain/download.py b/app/chain/download.py index 5176a7b1..78d8e9f6 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -8,7 +8,7 @@ from app.core.meta import MetaBase from app.db.downloadhistory_oper import DownloadHistoryOper from app.helper.torrent import TorrentHelper from app.log import logger -from app.schemas import ExistMediaInfo, NotExistMediaInfo +from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent from app.schemas.types import MediaType, TorrentStatus, EventType from app.utils.string import StringUtils @@ -530,3 +530,9 @@ class DownloadChain(ChainBase): f"{round(torrent.progress * 100, 1)}%") index += 1 self.post_message(title=title, text="\n".join(messages), userid=userid) + + def downloading(self) -> List[DownloadingTorrent]: + """ + 查询正在下载的任务 + """ + return self.list_torrents(status=TorrentStatus.DOWNLOADING) or []