@waline/vercel 1.4.0 → 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.4.0",
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,9 +36,10 @@ const {
36
36
  MAIL_TEMPLATE_ADMIN,
37
37
  QQ_TEMPLATE,
38
38
  TG_TEMPLATE,
39
+ WX_TEMPLATE,
39
40
  } = process.env;
40
41
 
41
- let storage = process'inspirecloud';
42
+ let storage = 'leancloud';
42
43
  let jwtKey = JWT_TOKEN || LEAN_KEY;
43
44
 
44
45
  if (LEAN_KEY) {
@@ -105,7 +106,7 @@ module.exports = {
105
106
  forbiddenWords,
106
107
  disallowIPList: [],
107
108
  secureDomains: SECURE_DOMAINS ? SECURE_DOMAINS.split(/\s*,\s*/) : undefined,
108
- disableUserAgent: !isFalse(DISABLE_USERAGENT),
109
+ disableUserAgent: DISABLE_USERAGENT && !isFalse(DISABLE_USERAGENT),
109
110
  avatarProxy,
110
111
  oauthUrl,
111
112
  markdown,
@@ -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
  };
@@ -3,6 +3,8 @@ const routerREST = require('think-router-rest');
3
3
  const isDev = think.env === 'development';
4
4
  const isTcb = think.env === 'cloudbase';
5
5
  const isDeta = think.env === 'deta' || process.env.DETA_RUNTIME === 'true';
6
+ const isAliyunFC =
7
+ think.env === 'aliyun-fc' || Boolean(process.env.FC_RUNTIME_VERSION);
6
8
 
7
9
  module.exports = [
8
10
  {
@@ -15,7 +17,7 @@ module.exports = [
15
17
  options: {
16
18
  logRequest: isDev,
17
19
  sendResponseTime: isDev,
18
- requestTimeoutCallback: isTcb || isDeta ? false : () => {},
20
+ requestTimeoutCallback: isTcb || isDeta || isAliyunFC ? false : () => {},
19
21
  },
20
22
  },
21
23
 
@@ -4,6 +4,7 @@ const BaseRest = require('./rest');
4
4
  const akismet = require('../service/akismet');
5
5
  const { getMarkdownParser } = require('../service/markdown');
6
6
 
7
+ const markdownParser = getMarkdownParser();
7
8
  async function formatCmt(
8
9
  { ua, user_id, ...comment },
9
10
  users = [],
@@ -39,6 +40,7 @@ async function formatCmt(
39
40
  comment.mail ? comment.mail.toLowerCase() : comment.mail
40
41
  );
41
42
 
43
+ comment.comment = markdownParser(comment.comment);
42
44
  return comment;
43
45
  }
44
46
 
@@ -49,8 +51,6 @@ module.exports = class extends BaseRest {
49
51
  `storage/${this.config('storage')}`,
50
52
  'Comment'
51
53
  );
52
-
53
- this.parser = getMarkdownParser();
54
54
  }
55
55
 
56
56
  async getAction() {
@@ -248,17 +248,14 @@ module.exports = class extends BaseRest {
248
248
  rid,
249
249
  ua,
250
250
  url,
251
+ comment,
251
252
  ip: this.ctx.ip,
252
253
  insertedAt: new Date(),
253
- comment: this.parser(comment),
254
254
  user_id: this.ctx.state.userInfo.objectId,
255
255
  };
256
256
 
257
257
  if (pid) {
258
- data.comment = data.comment.replace(
259
- '<p>',
260
- `<p><a class="at" href="#${pid}">@${at}</a>: `
261
- );
258
+ data.comment = `[@${at}](#${pid}): ` + data.comment;
262
259
  }
263
260
 
264
261
  think.logger.debug('Post Comment initial Data:', data);
@@ -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 });
@@ -16,7 +16,8 @@ module.exports = class extends Base {
16
16
  const parseKey = (k) => (k === 'objectId' ? '_id' : k);
17
17
  for (const k in where) {
18
18
  if (think.isString(where[k])) {
19
- _where[parseKey(k)] = k === 'objectId' ? this.db.ObjectId(where[k]) : where[k];
19
+ _where[parseKey(k)] =
20
+ k === 'objectId' ? this.db.ObjectId(where[k]) : where[k];
20
21
  continue;
21
22
  }
22
23
  if (where[k] === undefined) {