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

View File

@@ -485,8 +485,10 @@ class FileManagerModule(_ModuleBase):
return None, f"{fileitem.path} {target_storage} 重命名文件失败"
else:
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,
transfer_type: str) -> Tuple[bool, str]:
@@ -747,7 +749,7 @@ class FileManagerModule(_ModuleBase):
else:
logger.info(f"正在删除已存在的文件:{target_file}")
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,
target_storage=target_storage,
target_file=target_file,

View File

@@ -602,6 +602,7 @@ class AliPan(StorageBase):
if res:
download_url = res.json().get("url")
if not download_url:
logger.warn(f"{fileitem.path} 未获取到下载链接")
return None
res = RequestUtils().get_res(download_url)
if res:

View File

@@ -4,6 +4,7 @@ from typing import Union, Tuple
from pywebpush import webpush, WebPushException
from app.core.config import global_vars, settings
from app.helper.notification import NotificationHelper
from app.log import logger
from app.modules import _ModuleBase, _MessageBase
from app.schemas import Notification
@@ -11,7 +12,16 @@ from app.schemas import Notification
class WebPushModule(_ModuleBase, _MessageBase):
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
def get_name() -> str:
@@ -35,36 +45,40 @@ class WebPushModule(_ModuleBase, _MessageBase):
:param message: 消息内容
:return: 成功或失败
"""
if not message.title and not message.text:
logger.warn("标题和内容不能同时为空")
return
if not self.checkMessage(message):
logger.warn("WebPush 通道未启用")
return
try:
if message.title:
caption = message.title
content = message.text
else:
caption = message.text
content = ""
for sub in global_vars.get_subscriptions():
logger.debug(f"{sub} 发送WebPush{caption} {content}")
try:
webpush(
subscription_info=sub,
data=json.dumps({
"title": caption,
"body": content,
"url": message.link or "/?shotcut=message"
}),
vapid_private_key=settings.VAPID.get("privateKey"),
vapid_claims={
"sub": settings.VAPID.get("subject")
},
)
except WebPushException as err:
logger.error(f"WebPush发送失败: {str(err)}")
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:
logger.warn("标题和内容不能同时为空")
return
try:
if message.title:
caption = message.title
content = message.text
else:
caption = message.text
content = ""
for sub in global_vars.get_subscriptions():
logger.debug(f"{sub} 发送WebPush{caption} {content}")
try:
webpush(
subscription_info=sub,
data=json.dumps({
"title": caption,
"body": content,
"url": message.link or "/?shotcut=message"
}),
vapid_private_key=settings.VAPID.get("privateKey"),
vapid_claims={
"sub": settings.VAPID.get("subject")
},
)
except WebPushException as err:
logger.error(f"WebPush发送失败: {str(err)}")
except Exception as msg_e:
logger.error(f"发送消息失败:{msg_e}")
except Exception as msg_e:
logger.error(f"发送消息失败:{msg_e}")