fix 优化推荐跳转
feat 消息落库
This commit is contained in:
parent
06e4b9ad83
commit
6e607ca89f
@ -90,7 +90,7 @@ def movie_top250(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
浏览豆瓣剧集信息
|
浏览豆瓣剧集信息
|
||||||
"""
|
"""
|
||||||
movies = DoubanChain().movie_top250(page=page, count=count)
|
movies = DoubanChain().movie_top250(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
||||||
|
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ def tv_weekly_chinese(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
中国每周剧集口碑榜
|
中国每周剧集口碑榜
|
||||||
"""
|
"""
|
||||||
tvs = DoubanChain().tv_weekly_chinese(page=page, count=count)
|
tvs = DoubanChain().tv_weekly_chinese(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ def tv_weekly_global(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
全球每周剧集口碑榜
|
全球每周剧集口碑榜
|
||||||
"""
|
"""
|
||||||
tvs = DoubanChain().tv_weekly_global(page=page, count=count)
|
tvs = DoubanChain().tv_weekly_global(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ def tv_animation(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
热门动画剧集
|
热门动画剧集
|
||||||
"""
|
"""
|
||||||
tvs = DoubanChain().tv_animation(page=page, count=count)
|
tvs = DoubanChain().tv_animation(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ def movie_hot(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
热门电影
|
热门电影
|
||||||
"""
|
"""
|
||||||
movies = DoubanChain().movie_hot(page=page, count=count)
|
movies = DoubanChain().movie_hot(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
return [MediaInfo(douban_info=movie).to_dict() for movie in movies]
|
||||||
|
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ def tv_hot(page: int = 1,
|
|||||||
"""
|
"""
|
||||||
热门电视剧
|
热门电视剧
|
||||||
"""
|
"""
|
||||||
tvs = DoubanChain().tv_hot(page=page, count=count)
|
tvs = DoubanChain().tv_hot(page=page, count=count) or []
|
||||||
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
return [MediaInfo(douban_info=tv).to_dict() for tv in tvs]
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ def set_setting(key: str, value: Union[list, dict, bool, int, str] = None,
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/message", summary="实时消息")
|
@router.get("/message", summary="实时消息")
|
||||||
def get_message(token: str):
|
def get_message(token: str, role: str = "sys"):
|
||||||
"""
|
"""
|
||||||
实时获取系统消息,返回格式为SSE
|
实时获取系统消息,返回格式为SSE
|
||||||
"""
|
"""
|
||||||
@ -152,7 +152,7 @@ def get_message(token: str):
|
|||||||
|
|
||||||
def event_generator():
|
def event_generator():
|
||||||
while True:
|
while True:
|
||||||
detail = message.get()
|
detail = message.get(role)
|
||||||
yield 'data: %s\n\n' % (detail or '')
|
yield 'data: %s\n\n' % (detail or '')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from app.core.event import EventManager
|
|||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.module import ModuleManager
|
from app.core.module import ModuleManager
|
||||||
from app.db.message_oper import MessageOper
|
from app.db.message_oper import MessageOper
|
||||||
|
from app.helper.message import MessageHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent, CommingMessage, Notification, \
|
from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent, CommingMessage, Notification, \
|
||||||
WebhookEventInfo, TmdbEpisode
|
WebhookEventInfo, TmdbEpisode
|
||||||
@ -35,6 +36,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
self.modulemanager = ModuleManager()
|
self.modulemanager = ModuleManager()
|
||||||
self.eventmanager = EventManager()
|
self.eventmanager = EventManager()
|
||||||
self.messageoper = MessageOper()
|
self.messageoper = MessageOper()
|
||||||
|
self.messagehelper = MessageHelper()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_cache(filename: str) -> Any:
|
def load_cache(filename: str) -> Any:
|
||||||
@ -420,6 +422,7 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
"userid": message.userid,
|
"userid": message.userid,
|
||||||
})
|
})
|
||||||
# 保存消息
|
# 保存消息
|
||||||
|
self.messagehelper.put(message, role="user")
|
||||||
self.messageoper.add(channel=message.channel, mtype=message.mtype,
|
self.messageoper.add(channel=message.channel, mtype=message.mtype,
|
||||||
title=message.title, text=message.text,
|
title=message.title, text=message.text,
|
||||||
image=message.image, link=message.link,
|
image=message.image, link=message.link,
|
||||||
|
@ -1,19 +1,42 @@
|
|||||||
|
import json
|
||||||
import queue
|
import queue
|
||||||
|
from typing import Any, Union, Optional
|
||||||
|
|
||||||
|
from app.schemas import Notification
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
class MessageHelper(metaclass=Singleton):
|
class MessageHelper(metaclass=Singleton):
|
||||||
"""
|
"""
|
||||||
消息队列管理器
|
消息队列管理器,包括系统消息和用户消息
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.queue = queue.Queue()
|
self.sys_queue = queue.Queue()
|
||||||
|
self.user_queue = queue.Queue()
|
||||||
|
|
||||||
def put(self, message: str):
|
def put(self, message: Union[str, Notification], role: str = "sys"):
|
||||||
self.queue.put(message)
|
"""
|
||||||
|
存消息
|
||||||
|
:param message: 消息
|
||||||
|
:param role: 消息通道 sys/user
|
||||||
|
"""
|
||||||
|
if role == "sys":
|
||||||
|
self.sys_queue.put(message)
|
||||||
|
else:
|
||||||
|
if isinstance(message, Notification):
|
||||||
|
self.user_queue.put(json.dumps(message.dict()))
|
||||||
|
else:
|
||||||
|
self.user_queue.put(message)
|
||||||
|
|
||||||
def get(self):
|
def get(self, role: str = "sys") -> Optional[str]:
|
||||||
if not self.queue.empty():
|
"""
|
||||||
return self.queue.get(block=False)
|
取消息
|
||||||
|
:param role: 消息通道 sys/user
|
||||||
|
"""
|
||||||
|
if role == "sys":
|
||||||
|
if not self.sys_queue.empty():
|
||||||
|
return self.sys_queue.get(block=False)
|
||||||
|
else:
|
||||||
|
if not self.user_queue.empty():
|
||||||
|
return self.user_queue.get(block=False)
|
||||||
return None
|
return None
|
||||||
|
@ -43,7 +43,7 @@ class FileTransferModule(_ModuleBase):
|
|||||||
continue
|
continue
|
||||||
download_path = Path(path)
|
download_path = Path(path)
|
||||||
if not download_path.exists():
|
if not download_path.exists():
|
||||||
return False, f"目录 {download_path} 不存在"
|
return False, f"下载目录 {download_path} 不存在"
|
||||||
download_paths.append(path)
|
download_paths.append(path)
|
||||||
# 下载目录的设备ID
|
# 下载目录的设备ID
|
||||||
download_devids = [Path(path).stat().st_dev for path in download_paths]
|
download_devids = [Path(path).stat().st_dev for path in download_paths]
|
||||||
@ -54,7 +54,7 @@ class FileTransferModule(_ModuleBase):
|
|||||||
for path in settings.LIBRARY_PATHS:
|
for path in settings.LIBRARY_PATHS:
|
||||||
library_path = Path(path)
|
library_path = Path(path)
|
||||||
if not library_path.exists():
|
if not library_path.exists():
|
||||||
return False, f"目录不存在:{library_path}"
|
return False, f"媒体库目录不存在:{library_path}"
|
||||||
if settings.DOWNLOADER_MONITOR and settings.TRANSFER_TYPE == "link":
|
if settings.DOWNLOADER_MONITOR and settings.TRANSFER_TYPE == "link":
|
||||||
if library_path.stat().st_dev not in download_devids:
|
if library_path.stat().st_dev not in download_devids:
|
||||||
return False, f"媒体库目录 {library_path} " \
|
return False, f"媒体库目录 {library_path} " \
|
||||||
|
@ -38,6 +38,17 @@ class Notification(BaseModel):
|
|||||||
# 用户ID
|
# 用户ID
|
||||||
userid: Optional[Union[str, int]] = None
|
userid: Optional[Union[str, int]] = None
|
||||||
|
|
||||||
|
def dict(self):
|
||||||
|
return {
|
||||||
|
"channel": self.channel.value if self.channel else None,
|
||||||
|
"mtype": self.mtype.value if self.mtype else None,
|
||||||
|
"title": self.title,
|
||||||
|
"text": self.text,
|
||||||
|
"image": self.image,
|
||||||
|
"link": self.link,
|
||||||
|
"userid": self.userid
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class NotificationSwitch(BaseModel):
|
class NotificationSwitch(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user