From 61d44a6e7d1367b69e7e6c7bf38ee5c91b519b8a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 12 Aug 2023 18:11:20 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=BD=AC=E7=A7=BB=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=96=87=E4=BB=B6=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alembic/versions/ec5fb51fc300_1_0_2.py | 30 ++++++++++++++++++++++++++ app/chain/transfer.py | 7 ++++-- app/db/models/downloadhistory.py | 4 ++++ app/db/models/transferhistory.py | 2 ++ app/db/transferhistory_oper.py | 2 +- app/modules/filetransfer/__init__.py | 4 ++-- app/plugins/mediasyncdel/__init__.py | 1 + app/plugins/torrentremover/__init__.py | 4 ++-- app/schemas/transfer.py | 3 +-- 9 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 alembic/versions/ec5fb51fc300_1_0_2.py diff --git a/alembic/versions/ec5fb51fc300_1_0_2.py b/alembic/versions/ec5fb51fc300_1_0_2.py new file mode 100644 index 00000000..f7089b05 --- /dev/null +++ b/alembic/versions/ec5fb51fc300_1_0_2.py @@ -0,0 +1,30 @@ +"""1.0.2 + +Revision ID: ec5fb51fc300 +Revises: 14f1813ae8e3 +Create Date: 2023-08-12 17:55:06.509548 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ec5fb51fc300' +down_revision = '14f1813ae8e3' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + try: + with op.batch_alter_table("transferhistory") as batch_op: + batch_op.add_column(sa.Column('files', sa.String, nullable=True)) + except Exception as e: + pass + # ### end Alembic commands ### + + +def downgrade() -> None: + pass diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 973f63db..83e0a203 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -1,3 +1,4 @@ +import json import re import shutil from pathlib import Path @@ -167,7 +168,8 @@ class TransferChain(ChainBase): image=mediainfo.get_poster_image(), download_hash=torrent.hash, status=0, - errmsg=transferinfo.message if transferinfo else '未知错误' + errmsg=transferinfo.message if transferinfo else '未知错误', + files=json.dumps(transferinfo.file_list) if transferinfo else None ) continue # 新增转移成功历史记录 @@ -187,7 +189,8 @@ class TransferChain(ChainBase): episodes=meta.episode, image=mediainfo.get_poster_image(), download_hash=torrent.hash, - status=1 + status=1, + files=json.dumps(transferinfo.file_list) ) # 转移完成 self.transfer_completed(hashs=torrent.hash, transinfo=transferinfo) diff --git a/app/db/models/downloadhistory.py b/app/db/models/downloadhistory.py index 918312bc..979bdec1 100644 --- a/app/db/models/downloadhistory.py +++ b/app/db/models/downloadhistory.py @@ -45,3 +45,7 @@ class DownloadHistory(Base): @staticmethod def list_by_page(db: Session, page: int = 1, count: int = 30): return db.query(DownloadHistory).offset((page - 1) * count).limit(count).all() + + @staticmethod + def get_by_path(db: Session, path: str): + return db.query(DownloadHistory).filter(DownloadHistory.path == path).first() diff --git a/app/db/models/transferhistory.py b/app/db/models/transferhistory.py index d1eec1a6..c9334b8d 100644 --- a/app/db/models/transferhistory.py +++ b/app/db/models/transferhistory.py @@ -43,6 +43,8 @@ class TransferHistory(Base): errmsg = Column(String) # 时间 date = Column(String, index=True) + # 文件清单,以JSON存储 + files = Column(String) @staticmethod def list_by_title(db: Session, title: str, page: int = 1, count: int = 30): diff --git a/app/db/transferhistory_oper.py b/app/db/transferhistory_oper.py index 64d24173..da14af3a 100644 --- a/app/db/transferhistory_oper.py +++ b/app/db/transferhistory_oper.py @@ -15,7 +15,7 @@ class TransferHistoryOper(DbOper): 按标题查询转移记录 :param title: 数据key """ - return TransferHistory.search_by_title(self._db, title) + return TransferHistory.list_by_title(self._db, title) def get_by_src(self, src: str) -> Any: """ diff --git a/app/modules/filetransfer/__init__.py b/app/modules/filetransfer/__init__.py index 425ce203..e3039274 100644 --- a/app/modules/filetransfer/__init__.py +++ b/app/modules/filetransfer/__init__.py @@ -469,9 +469,9 @@ class FileTransferModule(_ModuleBase): fail_list.append(transfer_file) continue # 计算文件数 - file_list.append(str(new_file)) + file_list.append(str(transfer_file)) # 计算大小 - total_filesize += new_file.stat().st_size + total_filesize += transfer_file.stat().st_size except Exception as err: err_msgs.append(f"{transfer_file.name}:{err}") logger.error(f"{transfer_file}转移失败:{err}") diff --git a/app/plugins/mediasyncdel/__init__.py b/app/plugins/mediasyncdel/__init__.py index 4962858b..f23e18f2 100644 --- a/app/plugins/mediasyncdel/__init__.py +++ b/app/plugins/mediasyncdel/__init__.py @@ -45,6 +45,7 @@ class MediaSyncDel(_PluginBase): auth_level = 1 # 私有属性 + episode = None _scheduler: Optional[BackgroundScheduler] = None _enabled = False _sync_type: str = "" diff --git a/app/plugins/torrentremover/__init__.py b/app/plugins/torrentremover/__init__.py index 27c9fee3..b0fbd058 100644 --- a/app/plugins/torrentremover/__init__.py +++ b/app/plugins/torrentremover/__init__.py @@ -111,7 +111,7 @@ class TorrentRemover(_PluginBase): self._onlyonce = False # 保存设置 self.update_config({ - "enable": self._enabled, + "enabled": self._enabled, "notify": self._notify, "onlyonce": self._onlyonce, "action": self._action, @@ -132,7 +132,7 @@ class TorrentRemover(_PluginBase): }) def get_state(self) -> bool: - return self._enabled and True if self._cron and self._downloaders else False + return self._enabled and self._cron and self._downloaders @staticmethod def get_command() -> List[Dict[str, Any]]: diff --git a/app/schemas/transfer.py b/app/schemas/transfer.py index 245c0334..b04db74d 100644 --- a/app/schemas/transfer.py +++ b/app/schemas/transfer.py @@ -4,7 +4,6 @@ from typing import Optional from pydantic import BaseModel - class TransferTorrent(BaseModel): """ 待转移任务信息 @@ -60,4 +59,4 @@ class TransferInfo(BaseModel): dicts = vars(self).copy() # 创建一个字典的副本以避免修改原始数据 dicts["path"] = str(self.path) if self.path else None dicts["target_path"] = str(self.target_path) if self.target_path else None - return dicts \ No newline at end of file + return dicts