Merge branch 'jxxghp:main' into main

This commit is contained in:
s0mE 2024-03-16 15:36:20 +08:00 committed by GitHub
commit 4708fbb3cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 9 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

@ -27,10 +27,13 @@ class Message(Base):
reg_time = Column(String)
# 消息方向0-接收息1-发送消息
action = Column(Integer)
# 附件json
note = Column(String)
@staticmethod
@db_query
def list_by_page(db: Session, page: int = 1, count: int = 30):
result = db.query(Message).order_by(Message.reg_time.desc()).offset((page - 1) * count).limit(
count).all()
result.sort(key=lambda x: x.reg_time, reverse=False)
return list(result)

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,6 +289,29 @@ class Transmission:
logger.error(f"设置速度限制出错:{str(err)}")
return False
def get_speed_limit(self) -> Optional[Tuple[float, float]]:
"""
获取TR速度
:return: download_limit 下载速度 默认是0
upload_limit 上传速度 默认是0
"""
if not self.trc:
return None
download_limit = 0
upload_limit = 0
try:
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)}")
return (
download_limit,
upload_limit
)
def recheck_torrents(self, ids: Union[str, list]) -> bool:
"""
重新校验种子
@ -372,4 +395,3 @@ class Transmission:
except Exception as err:
logger.error(f"修改tracker出错{str(err)}")
return False