fix webpush
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
from typing import Union, Any, List
|
from typing import Union, Any, List
|
||||||
|
|
||||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
|
from fastapi import APIRouter, BackgroundTasks, Depends
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
from pywebpush import WebPushException, webpush
|
from pywebpush import WebPushException, webpush
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@ -174,8 +174,8 @@ def send_notification(payload: schemas.SubscriptionMessage, _: schemas.TokenPayl
|
|||||||
"""
|
"""
|
||||||
发送webpush通知
|
发送webpush通知
|
||||||
"""
|
"""
|
||||||
try:
|
for sub in global_vars.get_subscriptions():
|
||||||
for sub in global_vars.get_subscriptions():
|
try:
|
||||||
webpush(
|
webpush(
|
||||||
subscription_info=sub,
|
subscription_info=sub,
|
||||||
data=json.dumps(payload.dict()),
|
data=json.dumps(payload.dict()),
|
||||||
@ -184,7 +184,7 @@ def send_notification(payload: schemas.SubscriptionMessage, _: schemas.TokenPayl
|
|||||||
"sub": settings.VAPID.get("subject")
|
"sub": settings.VAPID.get("subject")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return schemas.Response(success=True)
|
except WebPushException as err:
|
||||||
except WebPushException as ex:
|
logger.error(f"WebPush发送失败: {str(err)}")
|
||||||
print("WebPush Error:", repr(ex))
|
continue
|
||||||
raise HTTPException(status_code=500, detail=str(ex))
|
return schemas.Response(success=True)
|
||||||
|
@ -61,7 +61,7 @@ class WebPushModule(_ModuleBase):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
except WebPushException as err:
|
except WebPushException as err:
|
||||||
print("WebPush Error:", str(err))
|
logger.error(f"WebPush发送失败: {str(err)}")
|
||||||
|
|
||||||
except Exception as msg_e:
|
except Exception as msg_e:
|
||||||
logger.error(f"发送消息失败:{msg_e}")
|
logger.error(f"发送消息失败:{msg_e}")
|
||||||
|
Reference in New Issue
Block a user