mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 14:09:43 +08:00
feat:ntfy增加可选的用户动作
This commit is contained in:
parent
f59e74f029
commit
054ff500ea
|
@ -153,6 +153,7 @@ export class NtfyNotification extends NotificationBaseInfo {
|
||||||
public ntfyToken = '';
|
public ntfyToken = '';
|
||||||
public ntfyUsername = '';
|
public ntfyUsername = '';
|
||||||
public ntfyPassword = '';
|
public ntfyPassword = '';
|
||||||
|
public ntfyActions = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WxPusherBotNotification extends NotificationBaseInfo {
|
export class WxPusherBotNotification extends NotificationBaseInfo {
|
||||||
|
|
|
@ -623,29 +623,35 @@ export default class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ntfy() {
|
private async ntfy() {
|
||||||
const { ntfyUrl, ntfyTopic, ntfyPriority, ntfyToken, ntfyUsername, ntfyPassword } = this.params;
|
const { ntfyUrl, ntfyTopic, ntfyPriority, ntfyToken, ntfyUsername, ntfyPassword, ntfyActions } = this.params;
|
||||||
// 编码函数
|
// 编码函数
|
||||||
const encodeRfc2047 = (text: string, charset: string = 'UTF-8'): string => {
|
const encodeRfc2047 = (text: string, charset: string = 'UTF-8'): string => {
|
||||||
const encodedText = Buffer.from(text).toString('base64');
|
const encodedText = Buffer.from(text).toString('base64');
|
||||||
return `=?${charset}?B?${encodedText}?=`;
|
return `=?${charset}?B?${encodedText}?=`;
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const encodedTitle = encodeRfc2047(this.title);
|
const headers: Record<string, string> = {
|
||||||
|
Title: encodeRfc2047(this.title),
|
||||||
|
Priority: `${ntfyPriority || '3'}`,
|
||||||
|
Icon: 'https://qn.whyour.cn/logo.png',
|
||||||
|
};
|
||||||
|
if (ntfyToken) {
|
||||||
|
headers['Authorization'] = `Bearer ${ntfyToken}`;
|
||||||
|
} else if (ntfyUsername && ntfyPassword) {
|
||||||
|
headers['Authorization'] = `Basic ${Buffer.from(`${ntfyUsername}:${ntfyPassword}`).toString('base64')}`;
|
||||||
|
}
|
||||||
|
if (ntfyActions) {
|
||||||
|
headers['Actions'] = ntfyActions;
|
||||||
|
}
|
||||||
const res = await httpClient.request(
|
const res = await httpClient.request(
|
||||||
`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`,
|
`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`,
|
||||||
{
|
{
|
||||||
...this.gotOption,
|
...this.gotOption,
|
||||||
body: `${this.content}`,
|
body: `${this.content}`,
|
||||||
headers: { Title: encodedTitle, Priority: `${ntfyPriority || '3'}`, Icon: 'https://qn.whyour.cn/logo.png'},
|
headers: headers,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (ntfyToken) {
|
|
||||||
res.headers['Authorization'] = `Bearer ${ntfyToken}`;
|
|
||||||
} else if (ntfyUsername && ntfyPassword) {
|
|
||||||
res.headers['Authorization'] = `Basic ${Buffer.from(`${ntfyUsername}:${ntfyPassword}`).toString('base64')}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -229,12 +229,14 @@ export QMSG_TYPE=""
|
||||||
## ntfy_token 填写推送token,可选
|
## ntfy_token 填写推送token,可选
|
||||||
## ntfy_username 填写推送用户名称,可选
|
## ntfy_username 填写推送用户名称,可选
|
||||||
## ntfy_password 填写推送用户密码,可选
|
## ntfy_password 填写推送用户密码,可选
|
||||||
|
## ntfy_actions 填写推送用户动作,可选
|
||||||
export NTFY_URL=""
|
export NTFY_URL=""
|
||||||
export NTFY_TOPIC=""
|
export NTFY_TOPIC=""
|
||||||
export NTFY_PRIORITY="3"
|
export NTFY_PRIORITY="3"
|
||||||
export NTFY_TOKEN=""
|
export NTFY_TOKEN=""
|
||||||
export NTFY_USERNAME=""
|
export NTFY_USERNAME=""
|
||||||
export NTFY_PASSWORD=""
|
export NTFY_PASSWORD=""
|
||||||
|
export NTFY_ACTIONS=""
|
||||||
|
|
||||||
## 21. wxPusher
|
## 21. wxPusher
|
||||||
## 官方文档: https://wxpusher.zjiecode.com/docs/
|
## 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||||
|
|
|
@ -143,6 +143,7 @@ const push_config = {
|
||||||
NTFY_TOKEN: '', // 推送token,可选
|
NTFY_TOKEN: '', // 推送token,可选
|
||||||
NTFY_USERNAME: '', // 推送用户名称,可选
|
NTFY_USERNAME: '', // 推送用户名称,可选
|
||||||
NTFY_PASSWORD: '', // 推送用户密码,可选
|
NTFY_PASSWORD: '', // 推送用户密码,可选
|
||||||
|
NTFY_ACTIONS: '', // 推送用户动作,可选
|
||||||
|
|
||||||
// 官方文档: https://wxpusher.zjiecode.com/docs/
|
// 官方文档: https://wxpusher.zjiecode.com/docs/
|
||||||
// 管理后台: https://wxpusher.zjiecode.com/admin/
|
// 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||||
|
@ -1261,7 +1262,7 @@ function ntfyNotify(text, desp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD } = push_config;
|
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD, NTFY_ACTIONS } = push_config;
|
||||||
if (NTFY_TOPIC) {
|
if (NTFY_TOPIC) {
|
||||||
const options = {
|
const options = {
|
||||||
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
||||||
|
@ -1278,6 +1279,9 @@ function ntfyNotify(text, desp) {
|
||||||
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
|
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
|
||||||
options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
|
options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
|
||||||
}
|
}
|
||||||
|
if (NTFY_ACTIONS) {
|
||||||
|
options.headers['Actions'] = NTFY_ACTIONS;
|
||||||
|
}
|
||||||
|
|
||||||
$.post(options, (err, resp, data) => {
|
$.post(options, (err, resp, data) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -129,6 +129,7 @@ push_config = {
|
||||||
'NTFY_TOKEN': '', # 推送token,可选
|
'NTFY_TOKEN': '', # 推送token,可选
|
||||||
'NTFY_USERNAME': '', # 推送用户名称,可选
|
'NTFY_USERNAME': '', # 推送用户名称,可选
|
||||||
'NTFY_PASSWORD': '', # 推送用户密码,可选
|
'NTFY_PASSWORD': '', # 推送用户密码,可选
|
||||||
|
'NTFY_ACTIONS': '', # 推送用户动作,可选
|
||||||
|
|
||||||
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
|
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
|
||||||
'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
|
||||||
|
@ -810,12 +811,13 @@ def ntfy(title: str, content: str) -> None:
|
||||||
|
|
||||||
data = content.encode(encoding="utf-8")
|
data = content.encode(encoding="utf-8")
|
||||||
headers = {"Title": encoded_title, "Priority": priority, "Icon": "https://qn.whyour.cn/logo.png"} # 使用编码后的 title
|
headers = {"Title": encoded_title, "Priority": priority, "Icon": "https://qn.whyour.cn/logo.png"} # 使用编码后的 title
|
||||||
if (push_config.get("NTFY_TOKEN")) {
|
if push_config.get("NTFY_TOKEN"):
|
||||||
headers['Authorization'] = "Bearer " + push_config.get("NTFY_TOKEN")
|
headers['Authorization'] = "Bearer " + push_config.get("NTFY_TOKEN")
|
||||||
} else if (push_config.get("NTFY_USERNAME") and push_config.get("NTFY_PASSWORD")) {
|
elif push_config.get("NTFY_USERNAME") and push_config.get("NTFY_PASSWORD"):
|
||||||
authStr = push_config.get("NTFY_USERNAME") + ":" + 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')
|
headers['Authorization'] = "Basic " + base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
|
||||||
}
|
if push_config.get("NTFY_ACTIONS"):
|
||||||
|
headers['Actions'] = push_config.get("NTFY_ACTIONS")
|
||||||
|
|
||||||
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
|
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
|
||||||
response = requests.post(url, data=data, headers=headers)
|
response = requests.post(url, data=data, headers=headers)
|
||||||
|
|
|
@ -395,10 +395,11 @@
|
||||||
"PushMe的Key,https://push.i-i.me/": "PushMe key, https://push.i-i.me/",
|
"PushMe的Key,https://push.i-i.me/": "PushMe key, https://push.i-i.me/",
|
||||||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface",
|
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface",
|
||||||
"ntfy的url地址,例如 https://ntfy.sh": "The URL address of ntfy, for example, https://ntfy.sh.",
|
"ntfy的url地址,例如 https://ntfy.sh": "The URL address of ntfy, for example, https://ntfy.sh.",
|
||||||
"ntfy的消息应用topic": "The topic for ntfy's messaging application.",
|
"ntfy应用topic": "The topic for ntfy's application.",
|
||||||
"ntfy的消息应用token": "The token for ntfy's messaging application, see https://docs.ntfy.sh/config/#access-tokens",
|
"ntfy应用token": "The token for ntfy's application, see https://docs.ntfy.sh/config/#access-tokens",
|
||||||
"ntfy的消息应用用户名": "The username for ntfy's messaging application, see https://docs.ntfy.sh/config/#users-and-roles",
|
"ntfy应用用户名": "The username for ntfy's application, see https://docs.ntfy.sh/config/#users-and-roles",
|
||||||
"ntfy的消息应用密码": "The password for ntfy's messaging application, see https://docs.ntfy.sh/config/#users-and-roles",
|
"ntfy应用密码": "The password for ntfy's application, see https://docs.ntfy.sh/config/#users-and-roles",
|
||||||
|
"ntfy用户动作": "The user actions for ntfy's application, up to three actions, see https://docs.ntfy.sh/publish/?h=actions#action-buttons",
|
||||||
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/",
|
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/",
|
||||||
"wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",
|
"wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",
|
||||||
"wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured",
|
"wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured",
|
||||||
|
|
|
@ -395,10 +395,11 @@
|
||||||
"PushMe的Key,https://push.i-i.me/": "PushMe的Key,https://push.i-i.me/",
|
"PushMe的Key,https://push.i-i.me/": "PushMe的Key,https://push.i-i.me/",
|
||||||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口",
|
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口",
|
||||||
"ntfy的url地址,例如 https://ntfy.sh": "ntfy的url地址,例如 https://ntfy.sh",
|
"ntfy的url地址,例如 https://ntfy.sh": "ntfy的url地址,例如 https://ntfy.sh",
|
||||||
"ntfy的消息应用topic": "ntfy的消息应用topic",
|
"ntfy应用topic": "ntfy应用topic",
|
||||||
"ntfy的消息应用token": "ntfy的消息应用token,参考 https://docs.ntfy.sh/config/#access-tokens",
|
"ntfy应用token": "ntfy应用token,参考 https://docs.ntfy.sh/config/#access-tokens",
|
||||||
"ntfy的消息应用用户名": "ntfy的消息应用用户名,参考 https://docs.ntfy.sh/config/#users-and-roles",
|
"ntfy应用用户名": "ntfy应用用户名,参考 https://docs.ntfy.sh/config/#users-and-roles",
|
||||||
"ntfy的消息应用密码": "ntfy的消息应用密码,参考 https://docs.ntfy.sh/config/#users-and-roles",
|
"ntfy应用密码": "ntfy应用密码,参考 https://docs.ntfy.sh/config/#users-and-roles",
|
||||||
|
"ntfy用户动作": "ntfy用户动作,最多三个动作,参考 https://docs.ntfy.sh/publish/?h=actions#action-buttons",
|
||||||
"wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/",
|
"wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/",
|
||||||
"wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行",
|
"wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行",
|
||||||
"wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行",
|
"wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行",
|
||||||
|
|
|
@ -128,13 +128,14 @@ export default {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'ntfyTopic',
|
label: 'ntfyTopic',
|
||||||
tip: intl.get('ntfy的消息应用topic'),
|
tip: intl.get('ntfy应用topic'),
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{ label: 'ntfyPriority', tip: intl.get('推送消息的优先级') },
|
{ label: 'ntfyPriority', tip: intl.get('推送消息的优先级') },
|
||||||
{ label: 'ntfyToken', tip: intl.get('ntfy的消息应用token') },
|
{ label: 'ntfyToken', tip: intl.get('ntfy应用token') },
|
||||||
{ label: 'ntfyUsername', tip: intl.get('ntfy的消息应用用户名') },
|
{ label: 'ntfyUsername', tip: intl.get('ntfy应用用户名') },
|
||||||
{ label: 'ntfyPassword', tip: intl.get('ntfy的消息应用密码') },
|
{ label: 'ntfyPassword', tip: intl.get('ntfy应用密码') },
|
||||||
|
{ label: 'ntfyActions', tip: intl.get('ntfy用户动作') },
|
||||||
],
|
],
|
||||||
chat: [
|
chat: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user