@waline/vercel 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "repository": "https://github.com/walinejs/waline",
6
6
  "license": "MIT",
@@ -36,6 +36,7 @@ const {
36
36
  MAIL_TEMPLATE_ADMIN,
37
37
  QQ_TEMPLATE,
38
38
  TG_TEMPLATE,
39
+ WX_TEMPLATE,
39
40
  } = process.env;
40
41
 
41
42
  let storage = 'leancloud';
@@ -115,4 +116,5 @@ module.exports = {
115
116
  mailTemplateAdmin: MAIL_TEMPLATE_ADMIN,
116
117
  QQTemplate: QQ_TEMPLATE,
117
118
  TGTemplate: TG_TEMPLATE,
119
+ WXTemplate: WX_TEMPLATE,
118
120
  };
@@ -91,6 +91,81 @@ module.exports = class extends think.Service {
91
91
  });
92
92
  }
93
93
 
94
+ async qywxAmWechat({ title, content }, self, parent) {
95
+ const { QYWX_AM, SITE_NAME, SITE_URL } = process.env;
96
+ if (!QYWX_AM) {
97
+ return false;
98
+ }
99
+
100
+ const QYWX_AM_AY = QYWX_AM.split(',');
101
+ const comment = self.comment
102
+ .replace(/<a href="(.*?)">(.*?)<\/a>/g, '\n[$2] $1\n')
103
+ .replace(/<[^>]+>/g, '');
104
+ const postName = self.url;
105
+
106
+ const data = {
107
+ self: {
108
+ ...self,
109
+ comment,
110
+ },
111
+ postName,
112
+ parent,
113
+ site: {
114
+ name: SITE_NAME,
115
+ url: SITE_URL,
116
+ postUrl: SITE_URL + self.url + '#' + self.objectId,
117
+ },
118
+ };
119
+ const contentWechat =
120
+ think.config('WXTemplate') ||
121
+ `💬 {{site.name|safe}}的文章《{{postName}}》有新评论啦
122
+ 【评论者昵称】:{{self.nick}}
123
+ 【评论者邮箱】:{{self.mail}}
124
+ 【内容】:{{self.comment}}
125
+ <a href='{{site.postUrl}}'>查看详情</a>`;
126
+
127
+ title = nunjucks.renderString(title, data);
128
+ const desp = nunjucks.renderString(contentWechat, data);
129
+ content = desp.replace(/\n/g, '<br/>');
130
+
131
+ const { access_token } = await request({
132
+ uri: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`,
133
+ qs: {
134
+ corpid: `${QYWX_AM_AY[0]}`,
135
+ corpsecret: `${QYWX_AM_AY[1]}`,
136
+ },
137
+ headers: {
138
+ 'Content-Type': 'application/json',
139
+ },
140
+ json: true,
141
+ });
142
+ return request({
143
+ url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${access_token}`,
144
+ body: {
145
+ touser: `${QYWX_AM_AY[2]}`,
146
+ agentid: `${QYWX_AM_AY[3]}`,
147
+ msgtype: 'mpnews',
148
+ mpnews: {
149
+ articles: [
150
+ {
151
+ title,
152
+ thumb_media_id: `${QYWX_AM_AY[4]}`,
153
+ author: `Waline Comment`,
154
+ content_source_url: `${data.site.postUrl}`,
155
+ content: `${content}`,
156
+ digest: `${desp}`,
157
+ },
158
+ ],
159
+ },
160
+ },
161
+ method: 'POST',
162
+ json: true,
163
+ headers: {
164
+ 'Content-Type': 'application/json',
165
+ },
166
+ });
167
+ }
168
+
94
169
  async qq(self, parent) {
95
170
  const { QMSG_KEY, QQ_ID, SITE_NAME, SITE_URL } = process.env;
96
171
  if (!QMSG_KEY) {
@@ -230,12 +305,18 @@ module.exports = class extends think.Service {
230
305
 
231
306
  if (!isAuthorComment && !disableAuthorNotify) {
232
307
  const wechat = await this.wechat({ title, content }, comment, parent);
308
+ const qywxAmWechat = await this.qywxAmWechat(
309
+ { title, content },
310
+ comment,
311
+ parent
312
+ );
233
313
  const qq = await this.qq(comment, parent);
234
314
  const telegram = await this.telegram(comment, parent);
235
315
  if (
236
316
  think.isEmpty(wechat) &&
237
317
  think.isEmpty(qq) &&
238
318
  think.isEmpty(telegram) &&
319
+ think.isEmpty(qywxAmWechat) &&
239
320
  !isReplyAuthor
240
321
  ) {
241
322
  mailList.push({ to: AUTHOR, title, content });