This commit is contained in:
jxxghp 2024-03-16 15:31:04 +08:00
parent d0af1bf075
commit 9acf05f334
7 changed files with 29 additions and 15 deletions

View File

@ -43,7 +43,7 @@ async def user_message(background_tasks: BackgroundTasks, request: Request):
@router.post("/web", summary="接收WEB消息", response_model=schemas.Response) @router.post("/web", summary="接收WEB消息", response_model=schemas.Response)
async def web_message(text: str, current_user: User = Depends(get_current_active_superuser)): def web_message(text: str, current_user: User = Depends(get_current_active_superuser)):
""" """
WEB消息响应 WEB消息响应
""" """

View File

@ -437,6 +437,12 @@ class ChainBase(metaclass=ABCMeta):
:param medias: 媒体列表 :param medias: 媒体列表
:return: 成功或失败 :return: 成功或失败
""" """
self.messagehelper.put(message, role="user")
self.messageoper.add(channel=message.channel, mtype=message.mtype,
title=message.title, text=message.text,
image=message.image, link=message.link,
userid=message.userid, action=1,
note=[media.to_dict() for media in medias])
return self.run_module("post_medias_message", message=message, medias=medias) return self.run_module("post_medias_message", message=message, medias=medias)
def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]: def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]:
@ -446,6 +452,12 @@ class ChainBase(metaclass=ABCMeta):
:param torrents: 种子列表 :param torrents: 种子列表
:return: 成功或失败 :return: 成功或失败
""" """
self.messagehelper.put(message, role="user")
self.messageoper.add(channel=message.channel, mtype=message.mtype,
title=message.title, text=message.text,
image=message.image, link=message.link,
userid=message.userid, action=1,
note=[torrent.to_dict() for torrent in torrents])
return self.run_module("post_torrents_message", message=message, torrents=torrents) return self.run_module("post_torrents_message", message=message, torrents=torrents)
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str, def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,

View File

@ -147,8 +147,7 @@ class MessageChain(ChainBase):
), role="user") ), role="user")
self.messageoper.add( self.messageoper.add(
channel=channel, channel=channel,
userid=userid, userid=username or userid,
username=username,
text=text, text=text,
action=0 action=0
) )

View File

@ -1,5 +1,6 @@
import json
import time import time
from typing import Optional, Union from typing import Optional
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
@ -25,6 +26,7 @@ class MessageOper(DbOper):
link: str = None, link: str = None,
userid: str = None, userid: str = None,
action: int = 1, action: int = 1,
note: dict = None,
**kwargs): **kwargs):
""" """
新增媒体服务器数据 新增媒体服务器数据
@ -36,6 +38,7 @@ class MessageOper(DbOper):
:param link: 链接 :param link: 链接
:param userid: 用户ID :param userid: 用户ID
:param action: 消息方向0-接收息1-发送消息 :param action: 消息方向0-接收息1-发送消息
:param note: 附件json
""" """
kwargs.update({ kwargs.update({
"channel": channel.value if channel else '', "channel": channel.value if channel else '',
@ -46,7 +49,8 @@ class MessageOper(DbOper):
"link": link, "link": link,
"userid": userid, "userid": userid,
"action": action, "action": action,
"reg_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) "reg_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"note": json.dumps(note or {})
}) })
Message(**kwargs).create(self._db) Message(**kwargs).create(self._db)

View File

@ -23,12 +23,12 @@ class Message(Base):
link = Column(String) link = Column(String)
# 用户ID # 用户ID
userid = Column(String) userid = Column(String)
# 用户名
username = Column(String)
# 登记时间 # 登记时间
reg_time = Column(String) reg_time = Column(String)
# 消息方向0-接收息1-发送消息 # 消息方向0-接收息1-发送消息
action = Column(Integer) action = Column(Integer)
# 附件json
note = Column(String)
@staticmethod @staticmethod
@db_query @db_query

View File

@ -372,13 +372,13 @@ class Qbittorrent:
logger.error(f"设置速度限制出错:{str(err)}") logger.error(f"设置速度限制出错:{str(err)}")
return False return False
def get_speed_limit(self): def get_speed_limit(self) -> Optional[Tuple[float, float]]:
""" """
获取QB速度 获取QB速度
:return: 返回download_limit 和upload_limit 默认是0 :return: 返回download_limit 和upload_limit 默认是0
""" """
if not self.qbc: if not self.qbc:
return False return None
download_limit = 0 download_limit = 0
upload_limit = 0 upload_limit = 0
@ -388,7 +388,7 @@ class Qbittorrent:
except Exception as err: except Exception as err:
logger.error(f"获取速度限制出错:{str(err)}") logger.error(f"获取速度限制出错:{str(err)}")
return (download_limit/1024, upload_limit/1024) return download_limit / 1024, upload_limit / 1024
def recheck_torrents(self, ids: Union[str, list]) -> bool: def recheck_torrents(self, ids: Union[str, list]) -> bool:
""" """

View File

@ -289,20 +289,20 @@ class Transmission:
logger.error(f"设置速度限制出错:{str(err)}") logger.error(f"设置速度限制出错:{str(err)}")
return False return False
def get_speed_limit(self): def get_speed_limit(self) -> Optional[Tuple[float, float]]:
""" """
获取TR速度 获取TR速度
:return: download_limit 下载速度 默认是0 :return: download_limit 下载速度 默认是0
upload_limit 上传速度 默认是0 upload_limit 上传速度 默认是0
""" """
if not self.trc: if not self.trc:
return False return None
download_limit = 0 download_limit = 0
upload_limit = 0 upload_limit = 0
try: try:
download_limit = self.trc.get_session().get(settings.TR_DOWN_LIMIT_FIELD_NAME) download_limit = self.trc.get_session().get('speed_limit_down')
upload_limit = self.trc.get_session().get(settings.TR_UP_LIMIT_FIELD_NAME) upload_limit = self.trc.get_session().get('speed_limit_up')
except Exception as err: except Exception as err:
logger.error(f"获取速度限制出错:{str(err)}") logger.error(f"获取速度限制出错:{str(err)}")
@ -395,4 +395,3 @@ class Transmission:
except Exception as err: except Exception as err:
logger.error(f"修改tracker出错{str(err)}") logger.error(f"修改tracker出错{str(err)}")
return False return False