feat 下载时记录文件清单

This commit is contained in:
jxxghp
2023-08-31 08:37:00 +08:00
parent f80e5739ca
commit 593211c037
8 changed files with 69 additions and 27 deletions

View File

@ -1,8 +1,8 @@
from pathlib import Path
from typing import Any
from typing import List
from app.db import DbOper
from app.db.models.downloadhistory import DownloadHistory
from app.db.models.downloadhistory import DownloadHistory, DownloadFiles
class DownloadHistoryOper(DbOper):
@ -10,28 +10,57 @@ class DownloadHistoryOper(DbOper):
下载历史管理
"""
def get_by_path(self, path: Path) -> Any:
def get_by_path(self, path: Path) -> DownloadHistory:
"""
按路径查询下载记录
:param path: 数据key
"""
return DownloadHistory.get_by_path(self._db, str(path))
def get_by_hash(self, download_hash: str) -> Any:
def get_by_hash(self, download_hash: str) -> DownloadHistory:
"""
按Hash查询下载记录
:param download_hash: 数据key
"""
return DownloadHistory.get_by_hash(self._db, download_hash)
def add(self, **kwargs):
def add(self, **kwargs) -> DownloadHistory:
"""
新增下载历史
"""
downloadhistory = DownloadHistory(**kwargs)
return downloadhistory.create(self._db)
def list_by_page(self, page: int = 1, count: int = 30):
def add_files(self, file_items: List[dict]):
"""
新增下载历史文件
"""
for file_item in file_items:
downloadfile = DownloadFiles(**file_item)
downloadfile.create(self._db)
def get_files_by_hash(self, download_hash: str) -> List[DownloadFiles]:
"""
按Hash查询下载文件记录
:param download_hash: 数据key
"""
return DownloadFiles.get_by_hash(self._db, download_hash)
def get_file_by_fullpath(self, fullpath: str) -> DownloadFiles:
"""
按fullpath查询下载文件记录
:param fullpath: 数据key
"""
return DownloadFiles.get_by_fullpath(self._db, fullpath)
def get_files_by_savepath(self, fullpath: str) -> List[DownloadFiles]:
"""
按savepath查询下载文件记录
:param fullpath: 数据key
"""
return DownloadFiles.get_by_savepath(self._db, fullpath)
def list_by_page(self, page: int = 1, count: int = 30) -> List[DownloadHistory]:
"""
分页查询下载历史
"""
@ -44,7 +73,7 @@ class DownloadHistoryOper(DbOper):
DownloadHistory.truncate(self._db)
def get_last_by(self, mtype=None, title: str = None, year: str = None,
season: str = None, episode: str = None, tmdbid=None):
season: str = None, episode: str = None, tmdbid=None) -> List[DownloadHistory]:
"""
按类型、标题、年份、季集查询下载记录
"""