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)
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消息响应
"""

View File

@ -437,6 +437,12 @@ class ChainBase(metaclass=ABCMeta):
:param medias: 媒体列表
: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)
def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]:
@ -446,6 +452,12 @@ class ChainBase(metaclass=ABCMeta):
:param torrents: 种子列表
: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)
def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str,

View File

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

View File

@ -1,5 +1,6 @@
import json
import time
from typing import Optional, Union
from typing import Optional
from sqlalchemy.orm import Session
@ -25,6 +26,7 @@ class MessageOper(DbOper):
link: str = None,
userid: str = None,
action: int = 1,
note: dict = None,
**kwargs):
"""
新增媒体服务器数据
@ -36,6 +38,7 @@ class MessageOper(DbOper):
:param link: 链接
:param userid: 用户ID
:param action: 消息方向0-接收息1-发送消息
:param note: 附件json
"""
kwargs.update({
"channel": channel.value if channel else '',
@ -46,7 +49,8 @@ class MessageOper(DbOper):
"link": link,
"userid": userid,
"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)

View File

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

View File

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

View File

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