fix webpush

This commit is contained in:
jxxghp
2024-09-21 17:59:39 +08:00
parent c51826ba4c
commit fada22e892
3 changed files with 52 additions and 35 deletions
+4 -2
View File
@@ -485,8 +485,10 @@ class FileManagerModule(_ModuleBase):
return None, f"{fileitem.path} {target_storage} 重命名文件失败" return None, f"{fileitem.path} {target_storage} 重命名文件失败"
else: else:
return None, f"{target_file.parent} {target_storage} 目录获取失败" return None, f"{target_file.parent} {target_storage} 目录获取失败"
else:
return None, f"网盘内只支持移动操作"
return None, "不支持的整理操作" return None, "未知错误"
def __transfer_other_files(self, fileitem: FileItem, target_storage: str, target_file: Path, def __transfer_other_files(self, fileitem: FileItem, target_storage: str, target_file: Path,
transfer_type: str) -> Tuple[bool, str]: transfer_type: str) -> Tuple[bool, str]:
@@ -747,7 +749,7 @@ class FileManagerModule(_ModuleBase):
else: else:
logger.info(f"正在删除已存在的文件:{target_file}") logger.info(f"正在删除已存在的文件:{target_file}")
target_file.unlink() target_file.unlink()
logger.info(f"正在整理文件:{fileitem.path}{target_file}") logger.info(f"正在整理文件:{fileitem.storage}{fileitem.path}{target_storage}{target_file}")
new_item, errmsg = self.__transfer_command(fileitem=fileitem, new_item, errmsg = self.__transfer_command(fileitem=fileitem,
target_storage=target_storage, target_storage=target_storage,
target_file=target_file, target_file=target_file,
@@ -602,6 +602,7 @@ class AliPan(StorageBase):
if res: if res:
download_url = res.json().get("url") download_url = res.json().get("url")
if not download_url: if not download_url:
logger.warn(f"{fileitem.path} 未获取到下载链接")
return None return None
res = RequestUtils().get_res(download_url) res = RequestUtils().get_res(download_url)
if res: if res:
+18 -4
View File
@@ -4,6 +4,7 @@ from typing import Union, Tuple
from pywebpush import webpush, WebPushException from pywebpush import webpush, WebPushException
from app.core.config import global_vars, settings from app.core.config import global_vars, settings
from app.helper.notification import NotificationHelper
from app.log import logger from app.log import logger
from app.modules import _ModuleBase, _MessageBase from app.modules import _ModuleBase, _MessageBase
from app.schemas import Notification from app.schemas import Notification
@@ -11,7 +12,16 @@ from app.schemas import Notification
class WebPushModule(_ModuleBase, _MessageBase): class WebPushModule(_ModuleBase, _MessageBase):
def init_module(self) -> None: def init_module(self) -> None:
pass """
初始化模块
"""
clients = NotificationHelper().get_clients()
if not clients:
return
self._configs = {}
for client in clients:
if client.type == "webpush" and client.enabled:
self._configs[client.name] = client
@staticmethod @staticmethod
def get_name() -> str: def get_name() -> str:
@@ -35,12 +45,16 @@ class WebPushModule(_ModuleBase, _MessageBase):
:param message: 消息内容 :param message: 消息内容
:return: 成功或失败 :return: 成功或失败
""" """
for conf in self._configs.values():
if not self.checkMessage(message, conf.name):
continue
webpush_users = conf.config.get("WEBPUSH_USERNAME")
if webpush_users:
if message.username and message.username != message.userid:
continue
if not message.title and not message.text: if not message.title and not message.text:
logger.warn("标题和内容不能同时为空") logger.warn("标题和内容不能同时为空")
return return
if not self.checkMessage(message):
logger.warn("WebPush 通道未启用")
return
try: try:
if message.title: if message.title:
caption = message.title caption = message.title