mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-11-04 19:39:48 +08:00 
			
		
		
		
	增加PushMe消息通道 (#2018),修复系统设置保存通知
This commit is contained in:
		
							parent
							
								
									56eb0c5408
								
							
						
					
					
						commit
						373b8c97d7
					
				| 
						 | 
					@ -15,6 +15,7 @@ export enum NotificationMode {
 | 
				
			||||||
  'iGot' = 'iGot',
 | 
					  'iGot' = 'iGot',
 | 
				
			||||||
  'pushPlus' = 'pushPlus',
 | 
					  'pushPlus' = 'pushPlus',
 | 
				
			||||||
  'email' = 'email',
 | 
					  'email' = 'email',
 | 
				
			||||||
 | 
					  'pushMe' = 'pushMe',
 | 
				
			||||||
  'feishu' = 'feishu',
 | 
					  'feishu' = 'feishu',
 | 
				
			||||||
  'webhook' = 'webhook',
 | 
					  'webhook' = 'webhook',
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -101,6 +102,10 @@ export class EmailNotification extends NotificationBaseInfo {
 | 
				
			||||||
  public emailPass: string = '';
 | 
					  public emailPass: string = '';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class PushMeNotification extends NotificationBaseInfo {
 | 
				
			||||||
 | 
					  public pushMeKey: string = '';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class WebhookNotification extends NotificationBaseInfo {
 | 
					export class WebhookNotification extends NotificationBaseInfo {
 | 
				
			||||||
  public webhookHeaders: string = '';
 | 
					  public webhookHeaders: string = '';
 | 
				
			||||||
  public webhookBody: string = '';
 | 
					  public webhookBody: string = '';
 | 
				
			||||||
| 
						 | 
					@ -131,5 +136,6 @@ export interface NotificationInfo
 | 
				
			||||||
    IGotNotification,
 | 
					    IGotNotification,
 | 
				
			||||||
    PushPlusNotification,
 | 
					    PushPlusNotification,
 | 
				
			||||||
    EmailNotification,
 | 
					    EmailNotification,
 | 
				
			||||||
 | 
					    PushMeNotification,
 | 
				
			||||||
    WebhookNotification,
 | 
					    WebhookNotification,
 | 
				
			||||||
    LarkNotification {}
 | 
					    LarkNotification {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ export default class NotificationService {
 | 
				
			||||||
    ['iGot', this.iGot],
 | 
					    ['iGot', this.iGot],
 | 
				
			||||||
    ['pushPlus', this.pushPlus],
 | 
					    ['pushPlus', this.pushPlus],
 | 
				
			||||||
    ['email', this.email],
 | 
					    ['email', this.email],
 | 
				
			||||||
 | 
					    ['pushMe', this.pushMe],
 | 
				
			||||||
    ['webhook', this.webhook],
 | 
					    ['webhook', this.webhook],
 | 
				
			||||||
    ['lark', this.lark],
 | 
					    ['lark', this.lark],
 | 
				
			||||||
  ]);
 | 
					  ]);
 | 
				
			||||||
| 
						 | 
					@ -561,6 +562,28 @@ export default class NotificationService {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private async pushMe() {
 | 
				
			||||||
 | 
					    const { pushMeKey } = this.params;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      const res: any = await got
 | 
				
			||||||
 | 
					        .post(`https://push.i-i.me/?push_key=${pushMeKey}`, {
 | 
				
			||||||
 | 
					          ...this.gotOption,
 | 
				
			||||||
 | 
					          json: {
 | 
				
			||||||
 | 
					            title: this.title,
 | 
				
			||||||
 | 
					            content: this.content
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          headers: { 'Content-Type': 'application/json' },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      if (res.body === 'success') {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        throw new Error(res.body);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (error: any) {
 | 
				
			||||||
 | 
					      throw new Error(error.response ? error.response.body : error);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private async webhook() {
 | 
					  private async webhook() {
 | 
				
			||||||
    const {
 | 
					    const {
 | 
				
			||||||
      webhookUrl,
 | 
					      webhookUrl,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,6 +141,11 @@ let SMTP_EMAIL = '';
 | 
				
			||||||
let SMTP_PASSWORD = '';
 | 
					let SMTP_PASSWORD = '';
 | 
				
			||||||
let SMTP_NAME = '';
 | 
					let SMTP_NAME = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// =======================================PushMe通知设置区域===========================================
 | 
				
			||||||
 | 
					//官方文档:https://push.i-i.me/
 | 
				
			||||||
 | 
					//此处填你的PushMe KEY.
 | 
				
			||||||
 | 
					let PUSHME_KEY = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//==========================云端环境变量的判断与接收=========================
 | 
					//==========================云端环境变量的判断与接收=========================
 | 
				
			||||||
if (process.env.GOTIFY_URL) {
 | 
					if (process.env.GOTIFY_URL) {
 | 
				
			||||||
  GOTIFY_URL = process.env.GOTIFY_URL;
 | 
					  GOTIFY_URL = process.env.GOTIFY_URL;
 | 
				
			||||||
| 
						 | 
					@ -288,6 +293,9 @@ if (process.env.SMTP_PASSWORD) {
 | 
				
			||||||
if (process.env.SMTP_NAME) {
 | 
					if (process.env.SMTP_NAME) {
 | 
				
			||||||
  SMTP_NAME = process.env.SMTP_NAME;
 | 
					  SMTP_NAME = process.env.SMTP_NAME;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					if (process.env.PUSHME_KEY) {
 | 
				
			||||||
 | 
					  PUSHME_KEY = process.env.PUSHME_KEY;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
//==========================云端环境变量的判断与接收=========================
 | 
					//==========================云端环境变量的判断与接收=========================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -336,6 +344,7 @@ async function sendNotify(
 | 
				
			||||||
    aibotkNotify(text, desp), //智能微秘书
 | 
					    aibotkNotify(text, desp), //智能微秘书
 | 
				
			||||||
    fsBotNotify(text, desp), //飞书机器人
 | 
					    fsBotNotify(text, desp), //飞书机器人
 | 
				
			||||||
    smtpNotify(text, desp), //SMTP 邮件
 | 
					    smtpNotify(text, desp), //SMTP 邮件
 | 
				
			||||||
 | 
					    PushMeNotify(text, desp), //PushMe
 | 
				
			||||||
  ]);
 | 
					  ]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1117,6 +1126,41 @@ function smtpNotify(text, desp) {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function PushMeNotify(text, desp) {
 | 
				
			||||||
 | 
					  return new Promise((resolve) => {
 | 
				
			||||||
 | 
					    if (PUSHME_KEY) {
 | 
				
			||||||
 | 
					      const options = {
 | 
				
			||||||
 | 
					        url: `https://push.i-i.me?push_key=${PUSHME_KEY}`,
 | 
				
			||||||
 | 
					        json: { title: text, content: desp },
 | 
				
			||||||
 | 
					        headers: {
 | 
				
			||||||
 | 
					          'Content-Type': 'application/json',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        timeout,
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					      $.post(options, (err, resp, data) => {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					          if (err) {
 | 
				
			||||||
 | 
					            console.log('PushMeNotify发送通知调用API失败!!\n');
 | 
				
			||||||
 | 
					            console.log(err);
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            if (data === 'success') {
 | 
				
			||||||
 | 
					              console.log('PushMe发送通知消息成功🎉\n');
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              console.log(`${data}\n`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        } catch (e) {
 | 
				
			||||||
 | 
					          $.logErr(e, resp);
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					          resolve(data);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      resolve();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  sendNotify,
 | 
					  sendNotify,
 | 
				
			||||||
  BARK_PUSH,
 | 
					  BARK_PUSH,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -98,6 +98,8 @@ push_config = {
 | 
				
			||||||
    'SMTP_EMAIL': '',                   # SMTP 收发件邮箱,通知将会由自己发给自己
 | 
					    'SMTP_EMAIL': '',                   # SMTP 收发件邮箱,通知将会由自己发给自己
 | 
				
			||||||
    'SMTP_PASSWORD': '',                # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
 | 
					    'SMTP_PASSWORD': '',                # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
 | 
				
			||||||
    'SMTP_NAME': '',                    # SMTP 收发件人姓名,可随意填写
 | 
					    'SMTP_NAME': '',                    # SMTP 收发件人姓名,可随意填写
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    'PUSHME_KEY': '',                     # PushMe 酱的 PUSHME_KEY
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
notify_function = []
 | 
					notify_function = []
 | 
				
			||||||
# fmt: on
 | 
					# fmt: on
 | 
				
			||||||
| 
						 | 
					@ -637,6 +639,27 @@ def smtp(title: str, content: str) -> None:
 | 
				
			||||||
    except Exception as e:
 | 
					    except Exception as e:
 | 
				
			||||||
        print(f"SMTP 邮件 推送失败!{e}")
 | 
					        print(f"SMTP 邮件 推送失败!{e}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def pushme(title: str, content: str) -> None:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    使用 PushMe 推送消息。
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    if not push_config.get("PUSHME_KEY"):
 | 
				
			||||||
 | 
					        print("PushMe 服务的 PUSHME_KEY 未设置!!\n取消推送")
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    print("PushMe 服务启动")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    url = f'https://push.i-i.me/?push_key={push_config.get("PUSHME_KEY")}'
 | 
				
			||||||
 | 
					    data = {
 | 
				
			||||||
 | 
					        "title": title,
 | 
				
			||||||
 | 
					        "content": content,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    response = requests.post(url, data=data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if response == 'success':
 | 
				
			||||||
 | 
					        print("PushMe 推送成功!")
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        print("PushMe 推送失败!{response}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def one() -> str:
 | 
					def one() -> str:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					@ -692,6 +715,8 @@ if (
 | 
				
			||||||
    and push_config.get("SMTP_NAME")
 | 
					    and push_config.get("SMTP_NAME")
 | 
				
			||||||
):
 | 
					):
 | 
				
			||||||
    notify_function.append(smtp)
 | 
					    notify_function.append(smtp)
 | 
				
			||||||
 | 
					if push_config.get("PUSHME_KEY"):
 | 
				
			||||||
 | 
					    notify_function.append(pushme)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def send(title: str, content: str) -> None:
 | 
					def send(title: str, content: str) -> None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,9 +50,7 @@ const Initialization = () => {
 | 
				
			||||||
  const submitNotification = (values: any) => {
 | 
					  const submitNotification = (values: any) => {
 | 
				
			||||||
    setLoading(true);
 | 
					    setLoading(true);
 | 
				
			||||||
    request
 | 
					    request
 | 
				
			||||||
      .put(`${config.apiPrefix}user/notification/init`, {
 | 
					      .put(`${config.apiPrefix}user/notification/init`, values)
 | 
				
			||||||
        values,
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
      .then(({ code, data }) => {
 | 
					      .then(({ code, data }) => {
 | 
				
			||||||
        if (code === 200) {
 | 
					        if (code === 200) {
 | 
				
			||||||
          next();
 | 
					          next();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,9 +19,7 @@ const NotificationSetting = ({ data }: any) => {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    request
 | 
					    request
 | 
				
			||||||
      .put(`${config.apiPrefix}user/notification`, {
 | 
					      .put(`${config.apiPrefix}user/notification`, values)
 | 
				
			||||||
        values,
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
      .then(({ code, data }) => {
 | 
					      .then(({ code, data }) => {
 | 
				
			||||||
        if (code === 200) {
 | 
					        if (code === 200) {
 | 
				
			||||||
          message.success(values.type ? '通知发送成功' : '通知关闭成功');
 | 
					          message.success(values.type ? '通知发送成功' : '通知关闭成功');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,7 @@ export default {
 | 
				
			||||||
    { value: 'chat', label: '群晖chat' },
 | 
					    { value: 'chat', label: '群晖chat' },
 | 
				
			||||||
    { value: 'email', label: '邮箱' },
 | 
					    { value: 'email', label: '邮箱' },
 | 
				
			||||||
    { value: 'lark', label: '飞书机器人' },
 | 
					    { value: 'lark', label: '飞书机器人' },
 | 
				
			||||||
 | 
					    { value: 'pushMe', label: 'PushMe' },
 | 
				
			||||||
    { value: 'webhook', label: '自定义通知' },
 | 
					    { value: 'webhook', label: '自定义通知' },
 | 
				
			||||||
    { value: 'closed', label: '已关闭' },
 | 
					    { value: 'closed', label: '已关闭' },
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
| 
						 | 
					@ -268,6 +269,13 @@ export default {
 | 
				
			||||||
      { label: 'emailUser', tip: '邮箱地址', required: true },
 | 
					      { label: 'emailUser', tip: '邮箱地址', required: true },
 | 
				
			||||||
      { label: 'emailPass', tip: '邮箱SMTP授权码', required: true },
 | 
					      { label: 'emailPass', tip: '邮箱SMTP授权码', required: true },
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
 | 
					    pushMe: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        label: 'pushMeKey',
 | 
				
			||||||
 | 
					        tip: 'PushMe的Key,https://push.i-i.me/',
 | 
				
			||||||
 | 
					        required: true,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
    webhook: [
 | 
					    webhook: [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        label: 'webhookMethod',
 | 
					        label: 'webhookMethod',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user