From 99c3de8b638ffe4985340703ff395d8e8b40a98e Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Wed, 12 Feb 2025 10:09:28 +0800 Subject: [PATCH] perfect: BarkMsg --- package.json | 6 +++--- plugins/barkmsg/__init__.py | 38 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 5b91db2..9321625 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "author": "thsrite", "level": 2, "history": { - "v2.4.3": "修复空签到失败问题", + "v2.4.3": "修复空签到失败问题", "v2.4.2": "修复PT时间签到失败问题", "v2.4.1": "修复海胆签到失败问题", "v2.4": "适配m-team Api地址变化", @@ -496,6 +496,7 @@ "level": 1, "v2": true, "history": { + "v1.3": "将标题、推送内容放入请求体中,避免编码后 URI 过长导致无法推送", "v1.2": "支持多人消息发送" } }, @@ -909,7 +910,6 @@ "v1.4.0": "修复强制更改IP时配置面板延时过长的问题。庆祝v2进入正式版,显示了一个没用的参数" } }, - "SyncCookieCloud": { "name": "同步CookieCloud", "description": "同步MoviePilot站点Cookie到本地CookieCloud。", @@ -955,4 +955,4 @@ "v1.3": "消息限流发送,以缓解IYUU服务器压力" } } -} +} \ No newline at end of file diff --git a/plugins/barkmsg/__init__.py b/plugins/barkmsg/__init__.py index 58f7df8..cbb0261 100644 --- a/plugins/barkmsg/__init__.py +++ b/plugins/barkmsg/__init__.py @@ -1,5 +1,5 @@ from typing import Any, List, Dict, Tuple -from urllib.parse import quote_plus +from urllib.parse import parse_qs from app.core.event import eventmanager, Event from app.log import logger @@ -16,7 +16,7 @@ class BarkMsg(_PluginBase): # 插件图标 plugin_icon = "Bark_A.png" # 插件版本 - plugin_version = "1.2" + plugin_version = "1.3" # 插件作者 plugin_author = "jxxghp" # 作者主页 @@ -217,23 +217,25 @@ class BarkMsg(_PluginBase): try: if not self._server or not self._apikey: return False, "参数未配置" - for apikey in self._apikey.split(): - sc_url = "%s/%s/%s/%s" % (self._server, apikey, quote_plus(title), quote_plus(text)) - if self._params: - sc_url = "%s?%s" % (sc_url, self._params) - res = RequestUtils().post_res(sc_url) - if res and res.status_code == 200: - ret_json = res.json() - code = ret_json['code'] - message = ret_json['message'] - if code == 200: - logger.info(f"{apikey} Bark消息发送成功") - else: - logger.warn(f"{apikey} Bark消息发送失败:{message}") - elif res is not None: - logger.warn(f"{apikey} Bark消息发送失败,错误码:{res.status_code},错误原因:{res.reason}") + req_body = {k: v[0] for k, v in parse_qs(self._params).items()} + req_body.update({ + "title": title, + "body": text, + "device_keys": self._apikey.split(), + }) + res = RequestUtils().post_res(f"{self._server}/push", json=req_body) + if res and res.status_code == 200: + ret_json = res.json() + code = ret_json['code'] + message = ret_json['message'] + if code == 200: + logger.info(f"Bark消息发送成功") else: - logger.warn(f"{apikey} Bark消息发送失败:未获取到返回信息") + logger.warn(f"Bark消息发送失败:{message}") + elif res is not None: + logger.warn(f"Bark消息发送失败,错误码:{res.status_code},错误原因:{res.reason}") + else: + logger.warn(f"Bark消息发送失败:未获取到返回信息") except Exception as msg_e: logger.error(f"Bark消息发送失败:{str(msg_e)}")