From 20eb0b4635476a1b760206aa785b2006730c3f88 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Mar 2024 16:29:14 +0800 Subject: [PATCH 1/4] fix message --- app/chain/__init__.py | 10 ++++++---- app/core/context.py | 1 + app/db/message_oper.py | 2 +- app/helper/message.py | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 60209c2a..02ce8886 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -437,12 +437,13 @@ class ChainBase(metaclass=ABCMeta): :param medias: 媒体列表 :return: 成功或失败 """ - self.messagehelper.put(message, role="user") + note_list = [media.to_dict() for media in medias] + self.messagehelper.put(message, role="user", note=note_list) 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]) + note=note_list) return self.run_module("post_medias_message", message=message, medias=medias) def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]: @@ -452,12 +453,13 @@ class ChainBase(metaclass=ABCMeta): :param torrents: 种子列表 :return: 成功或失败 """ - self.messagehelper.put(message, role="user") + note_list = [torrent.torrent_info.to_dict() for torrent in torrents] + self.messagehelper.put(message, role="user", note=note_list) 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]) + note=note_list) return self.run_module("post_torrents_message", message=message, torrents=torrents) def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str, diff --git a/app/core/context.py b/app/core/context.py index f5b0ca37..993f5c53 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -615,6 +615,7 @@ class MediaInfo: """ 返回字典 """ + self.clear() dicts = asdict(self) dicts["type"] = self.type.value if self.type else None dicts["detail_link"] = self.detail_link diff --git a/app/db/message_oper.py b/app/db/message_oper.py index 82d55b77..02863b17 100644 --- a/app/db/message_oper.py +++ b/app/db/message_oper.py @@ -50,7 +50,7 @@ class MessageOper(DbOper): "userid": userid, "action": action, "reg_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), - "note": json.dumps(note or {}) + "note": json.dumps(note) if note else '' }) Message(**kwargs).create(self._db) diff --git a/app/helper/message.py b/app/helper/message.py index f8606188..d609fdc5 100644 --- a/app/helper/message.py +++ b/app/helper/message.py @@ -14,11 +14,12 @@ class MessageHelper(metaclass=Singleton): self.sys_queue = queue.Queue() self.user_queue = queue.Queue() - def put(self, message: Any, role: str = "sys"): + def put(self, message: Any, role: str = "sys", note: dict = None): """ 存消息 :param message: 消息 :param role: 消息通道 sys/user + :param note: 附件json """ if role == "sys": self.sys_queue.put(message) @@ -28,6 +29,7 @@ class MessageHelper(metaclass=Singleton): elif hasattr(message, "to_dict"): content = message.to_dict() content['date'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + content['note'] = json.dumps(note) if note else None self.user_queue.put(json.dumps(content)) def get(self, role: str = "sys") -> Optional[str]: From 7ad498b3a363e6fc2e0389fab19e6d5ab7c74f8d Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Mar 2024 17:06:24 +0800 Subject: [PATCH 2/4] fix --- app/api/endpoints/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/endpoints/message.py b/app/api/endpoints/message.py index dc7ff07f..96ec71c3 100644 --- a/app/api/endpoints/message.py +++ b/app/api/endpoints/message.py @@ -49,7 +49,7 @@ def web_message(text: str, current_user: User = Depends(get_current_active_super """ MessageChain().handle_message( channel=MessageChannel.Web, - userid=current_user.id, + userid=current_user.name, username=current_user.name, text=text ) From f345d9400930fd150be78070340e907cf9938c17 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Mar 2024 18:28:09 +0800 Subject: [PATCH 3/4] fix README.md --- README.md | 10 +++++++--- app/api/servcookie.py | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2789fa9b..50eb178d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,11 @@ ### 2. **安装CookieCloud服务端(可选)** -MoviePilot内置了公共CookieCloud服务器,如果需要自建服务,可参考 [CookieCloud](https://github.com/easychen/CookieCloud) 项目进行搭建,docker镜像请点击 [这里](https://hub.docker.com/r/easychen/cookiecloud)。 +通过CookieCloud可以快速同步浏览器中保存的站点数据到MoviePilot,支持以下服务方式: + +- 使用公共CookieCloud服务器(默认):服务器地址为:https://movie-pilot.org/cookiecloud +- 使用内建的本地Cookie服务:设置`COOKIECLOUD_ENABLE_LOCAL`为`true`时启用,服务地址为:`http://localhost:${NGINX_PORT}/cookiecloud/`, Cookie数据加密保存在配置文件目录下的`cookies`文件中 +- 自建服务CookieCloud服务器:参考 [CookieCloud](https://github.com/easychen/CookieCloud) 项目进行搭建,docker镜像请点击 [这里](https://hub.docker.com/r/easychen/cookiecloud) **声明:** 本项目不会收集用户敏感数据,Cookie同步也是基于CookieCloud项目实现,非本项目提供的能力。技术角度上CookieCloud采用端到端加密,在个人不泄露`用户KEY`和`端对端加密密码`的情况下第三方无法窃取任何用户信息(包括服务器持有者)。如果你不放心,可以不使用公共服务或者不使用本项目,但如果使用后发生了任何信息泄露与本项目无关! @@ -221,10 +225,10 @@ location / { ``` - 反代使用ssl时,需要开启`http2`,否则会导致日志加载时间过长或不可用。以`Nginx`为例: ```nginx configuration -server{ +server { listen 443 ssl; http2 on; - ... + # ... } ``` - 新建的企业微信应用需要固定公网IP的代理才能收到消息,代理添加以下代码: diff --git a/app/api/servcookie.py b/app/api/servcookie.py index ab27009c..32c4648c 100644 --- a/app/api/servcookie.py +++ b/app/api/servcookie.py @@ -14,6 +14,8 @@ from app.utils.common import get_decrypted_cookie_data class GzipRequest(Request): + _body: bytes = b"" + async def body(self) -> bytes: if not hasattr(self, "_body"): body = await super().body() @@ -66,10 +68,9 @@ async def update_cookie(req: schemas.CookieData): content = json.dumps({"encrypted": req.encrypted}) with open(file_path, encoding="utf-8", mode="w") as file: file.write(content) - read_content = None with open(file_path, encoding="utf-8", mode="r") as file: read_content = file.read() - if (read_content == content): + if read_content == content: return {"action": "done"} else: return {"action": "error"} From aaa1b80edf19de9c0c9de7cb6589f829daf79d9c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Mar 2024 18:38:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=20=E8=B5=84=E6=BA=90=E5=8C=85=E6=9B=B4?= =?UTF-8?q?=E6=96=B0Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helper/resource.py | 2 +- app/utils/system.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helper/resource.py b/app/helper/resource.py index 20e9213f..9188231f 100644 --- a/app/helper/resource.py +++ b/app/helper/resource.py @@ -55,7 +55,7 @@ class ResourceHelper(metaclass=Singleton): target = resource.get("target") version = resource.get("version") # 判断平台 - if platform and platform != SystemUtils.platform: + if platform and platform != SystemUtils.platform(): continue # 判断本地是否存在 local_path = self._base_dir / target / rname diff --git a/app/utils/system.py b/app/utils/system.py index 3d2fb500..620c1d30 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -71,8 +71,8 @@ class SystemUtils: """ return True if platform.machine() == 'aarch64' else False - @property - def platform(self) -> str: + @staticmethod + def platform() -> str: """ 获取系统平台 """