mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
ntfy 增加可选的认证与用户动作 (#2741)
* feat:ntfy增加可选的认证 * feat:ntfy增加可选的用户动作 * fix:ntfy动作包含中文报错
This commit is contained in:
@@ -226,9 +226,17 @@ export QMSG_TYPE=""
|
||||
## ntfy_url 填写ntfy地址,如https://ntfy.sh
|
||||
## ntfy_topic 填写ntfy的消息应用topic
|
||||
## ntfy_priority 填写推送消息优先级,默认为3
|
||||
## ntfy_token 填写推送token,可选
|
||||
## ntfy_username 填写推送用户名称,可选
|
||||
## ntfy_password 填写推送用户密码,可选
|
||||
## ntfy_actions 填写推送用户动作,可选
|
||||
export NTFY_URL=""
|
||||
export NTFY_TOPIC=""
|
||||
export NTFY_PRIORITY="3"
|
||||
export NTFY_TOKEN=""
|
||||
export NTFY_USERNAME=""
|
||||
export NTFY_PASSWORD=""
|
||||
export NTFY_ACTIONS=""
|
||||
|
||||
## 21. wxPusher
|
||||
## 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||
|
||||
+15
-1
@@ -140,6 +140,10 @@ const push_config = {
|
||||
NTFY_URL: '', // ntfy地址,如https://ntfy.sh,默认为https://ntfy.sh
|
||||
NTFY_TOPIC: '', // ntfy的消息应用topic
|
||||
NTFY_PRIORITY: '3', // 推送消息优先级,默认为3
|
||||
NTFY_TOKEN: '', // 推送token,可选
|
||||
NTFY_USERNAME: '', // 推送用户名称,可选
|
||||
NTFY_PASSWORD: '', // 推送用户密码,可选
|
||||
NTFY_ACTIONS: '', // 推送用户动作,可选
|
||||
|
||||
// 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||
// 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||
@@ -1258,7 +1262,7 @@ function ntfyNotify(text, desp) {
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY } = push_config;
|
||||
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD, NTFY_ACTIONS } = push_config;
|
||||
if (NTFY_TOPIC) {
|
||||
const options = {
|
||||
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
||||
@@ -1266,9 +1270,19 @@ function ntfyNotify(text, desp) {
|
||||
headers: {
|
||||
Title: `${encodeRFC2047(text)}`,
|
||||
Priority: NTFY_PRIORITY || '3',
|
||||
Icon: 'https://qn.whyour.cn/logo.png',
|
||||
},
|
||||
timeout,
|
||||
};
|
||||
if (NTFY_TOKEN) {
|
||||
options.headers['Authorization'] = `Bearer ${NTFY_TOKEN}`;
|
||||
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
|
||||
options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
|
||||
}
|
||||
if (NTFY_ACTIONS) {
|
||||
options.headers['Actions'] = encodeRFC2047(NTFY_ACTIONS);
|
||||
}
|
||||
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
|
||||
+12
-1
@@ -126,6 +126,10 @@ push_config = {
|
||||
'NTFY_URL': '', # ntfy地址,如https://ntfy.sh
|
||||
'NTFY_TOPIC': '', # ntfy的消息应用topic
|
||||
'NTFY_PRIORITY':'3', # 推送消息优先级,默认为3
|
||||
'NTFY_TOKEN': '', # 推送token,可选
|
||||
'NTFY_USERNAME': '', # 推送用户名称,可选
|
||||
'NTFY_PASSWORD': '', # 推送用户密码,可选
|
||||
'NTFY_ACTIONS': '', # 推送用户动作,可选
|
||||
|
||||
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||
'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||
@@ -806,7 +810,14 @@ def ntfy(title: str, content: str) -> None:
|
||||
encoded_title = encode_rfc2047(title)
|
||||
|
||||
data = content.encode(encoding="utf-8")
|
||||
headers = {"Title": encoded_title, "Priority": priority} # 使用编码后的 title
|
||||
headers = {"Title": encoded_title, "Priority": priority, "Icon": "https://qn.whyour.cn/logo.png"} # 使用编码后的 title
|
||||
if push_config.get("NTFY_TOKEN"):
|
||||
headers['Authorization'] = "Bearer " + push_config.get("NTFY_TOKEN")
|
||||
elif push_config.get("NTFY_USERNAME") and push_config.get("NTFY_PASSWORD"):
|
||||
authStr = push_config.get("NTFY_USERNAME") + ":" + push_config.get("NTFY_PASSWORD")
|
||||
headers['Authorization'] = "Basic " + base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
|
||||
if push_config.get("NTFY_ACTIONS"):
|
||||
headers['Actions'] = encode_rfc2047(push_config.get("NTFY_ACTIONS"))
|
||||
|
||||
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
|
||||
response = requests.post(url, data=data, headers=headers)
|
||||
|
||||
Reference in New Issue
Block a user