diff --git a/workflows/utils/dingding.js b/workflows/utils/dingding.js deleted file mode 100644 index 0506598a..00000000 --- a/workflows/utils/dingding.js +++ /dev/null @@ -1,23 +0,0 @@ -const axios = require("axios"); - -const env = require("./env"); -async function dingding({ subject, text, html }) { - return axios - .post( - env.DINGDING_WEBHOOK, - { - msgtype: "text", - text: { - content: `${subject}\n${text || html}` - } - }, - { - headers: { - "Content-Type": "application/json" - } - } - ) - .then(res => console.log(JSON.stringify(res.data))); -} - -module.exports = dingding; diff --git a/workflows/utils/email.js b/workflows/utils/email.js deleted file mode 100644 index 34a74951..00000000 --- a/workflows/utils/email.js +++ /dev/null @@ -1,63 +0,0 @@ -const nodemailer = require("nodemailer"); -const path = require("path"); - -async function main({ subject, text, html }) { - const env = require("./env"); - - const auth = { - user: env.EMAIL_USER, // generated ethereal user - pass: env.EMAIL_PASS // generated ethereal password - }; - - if (!auth.user || !auth.pass) { - console.warn("邮箱功能不可用, 请先配置邮箱用户和密码"); - return; - } - - const transporter = nodemailer.createTransport({ - host: "smtp." + auth.user.match(/@(.*)/)[1], - secure: true, - port: 465, - auth, - tls: { - // do not fail on invalid certs - rejectUnauthorized: false - } - }); - - const template = ` -
-
- 稀土掘金 -
-
- ${html ? html : `
${text}
`} -
- -
- `.trim(); - - await transporter.sendMail({ - from: `稀土掘金助手 <${auth.user}>`, // sender address('"Fred Foo 👻" ') - to: env.EMAIL_TO, // list of receivers - subject, // Subject line - // text, // plain text body - html: template, // html body - attachments: [ - { - filename: "logo.svg", - path: path.resolve(__dirname, "../../resources/logo.svg"), - cid: "logo.svg" //same cid value as in the html img src - } - ] - }); - - console.log("已通知订阅人!"); -} - -module.exports = main; - -// main().catch(console.error); diff --git a/workflows/utils/pushMessage.js b/workflows/utils/pushMessage.js deleted file mode 100644 index cad649ec..00000000 --- a/workflows/utils/pushMessage.js +++ /dev/null @@ -1,14 +0,0 @@ -const env = require("./env"); -const email = require("./email"); -const pushplus = require("./pushplus"); -const dingding = require("./dingding"); -const weixinrobot = require("./weixinrobot"); - -async function pushMessage({ subject, text, html }) { - env.EMAIL_USER && (await email({ subject, text, html })); - env.DINGDING_WEBHOOK && (await dingding({ subject, text, html })); - env.PUSHPLUS_TOKEN && (await pushplus({ subject, text, html })); - env.WEIXIN_WEBHOOK && (await weixinrobot({ subject, text, html })); -} - -module.exports = pushMessage; diff --git a/workflows/utils/pushplus.js b/workflows/utils/pushplus.js deleted file mode 100644 index 65b2be54..00000000 --- a/workflows/utils/pushplus.js +++ /dev/null @@ -1,41 +0,0 @@ -const axios = require("axios"); -const env = require("./env"); -const userConfig = { - url: "http://www.pushplus.plus/send", - token: env.PUSHPLUS_TOKEN -}; - -async function main({ subject, text, html }) { - if (!userConfig.token) { - console.warn("未配置PushPlus之Token, 请先配置PushPlus"); - return; - } - return await postMessage({ - token: userConfig.token, - title: subject, - content: text || html, - topic: "", - template: "html", - channel: "wechat", - webhook: "", - callbackUrl: "", - timestamp: "" - }) - .then(res => res.data) - .then(json => { - console.log(`PushPlus推送结果: ` + json.msg); - return json; - }); -} - -async function postMessage(message) { - return await axios - .post(userConfig.url, message, { - headers: { - "Content-Type": "application/json" - } - }) - .catch(err => console.log(err)); -} - -module.exports = main; diff --git a/workflows/utils/weixinrobot.js b/workflows/utils/weixinrobot.js deleted file mode 100644 index af6e15c0..00000000 --- a/workflows/utils/weixinrobot.js +++ /dev/null @@ -1,20 +0,0 @@ -const axios = require("axios"); - -const env = require("./env"); - -async function weixinrobot({ subject, text, html }) { - axios - .post(env.WEIXIN_WEBHOOK, { - msgtype: "text", - text: { - content: `${subject}\n${text || html}` - } - }) - .then(response => { - console.log(response.data); - }) - .catch(error => { - console.log(error); - }); -} -module.exports = weixinrobot;