From 5fc7a7dd8a3e82d4b5d46611dcd92020ed233708 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 20 Oct 2023 08:07:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8Dv1.3.5=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/downloadhistory_oper.py | 5 ++--- app/db/models/__init__.py | 3 +-- app/db/plugindata_oper.py | 6 ++---- app/db/transferhistory_oper.py | 7 ++++--- app/plugins/__init__.py | 5 ++--- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/db/downloadhistory_oper.py b/app/db/downloadhistory_oper.py index b5dacf06..de7c1623 100644 --- a/app/db/downloadhistory_oper.py +++ b/app/db/downloadhistory_oper.py @@ -24,12 +24,11 @@ class DownloadHistoryOper(DbOper): """ return DownloadHistory.get_by_hash(self._db, download_hash) - def add(self, **kwargs) -> DownloadHistory: + def add(self, **kwargs): """ 新增下载历史 """ - downloadhistory = DownloadHistory(**kwargs) - return downloadhistory.create(self._db) + DownloadHistory(**kwargs).create(self._db) def add_files(self, file_items: List[dict]): """ diff --git a/app/db/models/__init__.py b/app/db/models/__init__.py index 5794ef59..067d2559 100644 --- a/app/db/models/__init__.py +++ b/app/db/models/__init__.py @@ -12,9 +12,8 @@ class Base: __name__: str @db_update - def create(self, db: Session) -> Self: + def create(self, db: Session): db.add(self) - return self @classmethod @db_query diff --git a/app/db/plugindata_oper.py b/app/db/plugindata_oper.py index 4f2c29c0..b66df994 100644 --- a/app/db/plugindata_oper.py +++ b/app/db/plugindata_oper.py @@ -11,7 +11,7 @@ class PluginDataOper(DbOper): 插件数据管理 """ - def save(self, plugin_id: str, key: str, value: Any) -> PluginData: + def save(self, plugin_id: str, key: str, value: Any): """ 保存插件数据 :param plugin_id: 插件id @@ -25,10 +25,8 @@ class PluginDataOper(DbOper): plugin.update(self._db, { "value": value }) - return plugin else: - plugin = PluginData(plugin_id=plugin_id, key=key, value=value) - return plugin.create(self._db) + PluginData(plugin_id=plugin_id, key=key, value=value).create(self._db) def get_data(self, plugin_id: str, key: str) -> Any: """ diff --git a/app/db/transferhistory_oper.py b/app/db/transferhistory_oper.py index e0ad09e2..247b22eb 100644 --- a/app/db/transferhistory_oper.py +++ b/app/db/transferhistory_oper.py @@ -43,14 +43,14 @@ class TransferHistoryOper(DbOper): """ return TransferHistory.list_by_hash(self._db, download_hash) - def add(self, **kwargs) -> TransferHistory: + def add(self, **kwargs): """ 新增转移历史 """ kwargs.update({ "date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) }) - return TransferHistory(**kwargs).create(self._db) + TransferHistory(**kwargs).create(self._db) def statistic(self, days: int = 7) -> List[Any]: """ @@ -103,7 +103,8 @@ class TransferHistoryOper(DbOper): kwargs.update({ "date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) }) - return TransferHistory(**kwargs).create(self._db) + TransferHistory(**kwargs).create(self._db) + return TransferHistory.get_by_src(self._db, kwargs.get("src")) def update_download_hash(self, historyid, download_hash): """ diff --git a/app/plugins/__init__.py b/app/plugins/__init__.py index 33feb4a6..9e5e31a0 100644 --- a/app/plugins/__init__.py +++ b/app/plugins/__init__.py @@ -5,7 +5,6 @@ from typing import Any, List, Dict, Tuple from app.chain import ChainBase from app.core.config import settings from app.core.event import EventManager -from app.db.models import Base from app.db.plugindata_oper import PluginDataOper from app.db.systemconfig_oper import SystemConfigOper from app.helper.message import MessageHelper @@ -141,7 +140,7 @@ class _PluginBase(metaclass=ABCMeta): data_path.mkdir(parents=True) return data_path - def save_data(self, key: str, value: Any, plugin_id: str = None) -> Base: + def save_data(self, key: str, value: Any, plugin_id: str = None): """ 保存插件数据 :param key: 数据key @@ -150,7 +149,7 @@ class _PluginBase(metaclass=ABCMeta): """ if not plugin_id: plugin_id = self.__class__.__name__ - return self.plugindata.save(plugin_id, key, value) + self.plugindata.save(plugin_id, key, value) def get_data(self, key: str, plugin_id: str = None) -> Any: """