@waline/vercel 1.13.6 → 1.14.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 +1 -1
- package/src/config/extend.js +14 -6
- package/src/controller/comment.js +12 -8
- package/src/controller/db.js +1 -1
- package/src/controller/token/2fa.js +1 -1
- package/src/controller/user/password.js +7 -2
- package/src/controller/user.js +32 -16
- package/src/controller/verification.js +3 -3
- package/src/extend/controller.js +11 -0
- package/src/locales/en.json +15 -0
- package/src/locales/index.js +12 -0
- package/src/locales/zh-CN.json +15 -0
- package/src/locales/zh-TW.json +15 -0
package/package.json
CHANGED
package/src/config/extend.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const Model = require('think-model');
|
|
2
2
|
const Mongo = require('think-mongo');
|
|
3
|
+
const request = require('request-promise-native');
|
|
3
4
|
|
|
4
5
|
module.exports = [
|
|
5
6
|
Model(think.app),
|
|
@@ -15,13 +16,20 @@ module.exports = [
|
|
|
15
16
|
const { protocol, host } = this;
|
|
16
17
|
return `${protocol}://${host}`;
|
|
17
18
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.ctx.status = 500;
|
|
19
|
+
async webhook(type, data) {
|
|
20
|
+
const { WEBHOOK } = process.env;
|
|
21
|
+
if (!WEBHOOK) {
|
|
22
|
+
return;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
return request({
|
|
26
|
+
uri: WEBHOOK,
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: {
|
|
29
|
+
'content-type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify({ type, data }),
|
|
32
|
+
});
|
|
25
33
|
},
|
|
26
34
|
},
|
|
27
35
|
},
|
|
@@ -388,7 +388,7 @@ module.exports = class extends BaseRest {
|
|
|
388
388
|
'The comment author had post same comment content before'
|
|
389
389
|
);
|
|
390
390
|
|
|
391
|
-
return this.fail('Duplicate Content');
|
|
391
|
+
return this.fail(this.locale('Duplicate Content'));
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
think.logger.debug('Comment duplicate check OK!');
|
|
@@ -403,7 +403,7 @@ module.exports = class extends BaseRest {
|
|
|
403
403
|
|
|
404
404
|
if (!think.isEmpty(recent)) {
|
|
405
405
|
think.logger.debug(`The author has posted in ${IPQPS} seconeds.`);
|
|
406
|
-
return this.fail('Comment too fast!');
|
|
406
|
+
return this.fail(this.locale('Comment too fast!'));
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
think.logger.debug(`Comment post frequence check OK!`);
|
|
@@ -460,21 +460,25 @@ module.exports = class extends BaseRest {
|
|
|
460
460
|
|
|
461
461
|
think.logger.debug(`Comment have been added to storage.`);
|
|
462
462
|
|
|
463
|
-
let
|
|
464
|
-
|
|
463
|
+
let parentComment;
|
|
465
464
|
if (pid) {
|
|
466
|
-
|
|
467
|
-
|
|
465
|
+
parentComment = await this.modelInstance.select({ objectId: pid });
|
|
466
|
+
parentComment = parentComment[0];
|
|
468
467
|
}
|
|
469
468
|
|
|
469
|
+
await this.ctx.webhook('new_comment', {
|
|
470
|
+
comment: { ...resp, rawComment: comment },
|
|
471
|
+
reply: parentComment,
|
|
472
|
+
});
|
|
473
|
+
|
|
470
474
|
if (comment.status !== 'spam') {
|
|
471
475
|
const notify = this.service('notify');
|
|
472
|
-
await notify.run({ ...resp, rawComment: comment },
|
|
476
|
+
await notify.run({ ...resp, rawComment: comment }, parentComment);
|
|
473
477
|
}
|
|
474
478
|
|
|
475
479
|
think.logger.debug(`Comment notify done!`);
|
|
476
480
|
|
|
477
|
-
await this.hook('postSave', resp,
|
|
481
|
+
await this.hook('postSave', resp, parentComment);
|
|
478
482
|
|
|
479
483
|
think.logger.debug(`Comment post hooks postSave done!`);
|
|
480
484
|
|
package/src/controller/db.js
CHANGED
|
@@ -35,7 +35,7 @@ module.exports = class extends BaseRest {
|
|
|
35
35
|
const jsonText = await readFileAsync(file.path, 'utf-8');
|
|
36
36
|
const importData = JSON.parse(jsonText);
|
|
37
37
|
if (!importData || importData.type !== 'waline') {
|
|
38
|
-
return this.fail('import data format not support!');
|
|
38
|
+
return this.fail(this.locale('import data format not support!'));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
for (let i = 0; i < importData.tables.length; i++) {
|
|
@@ -36,8 +36,13 @@ module.exports = class extends BaseRest {
|
|
|
36
36
|
? `"${SENDER_NAME}" <${SENDER_EMAIL}>`
|
|
37
37
|
: SMTP_USER,
|
|
38
38
|
to: user[0].email,
|
|
39
|
-
subject:
|
|
40
|
-
|
|
39
|
+
subject: this.locale('[{{name}}] Reset Password', {
|
|
40
|
+
name: SITE_NAME || 'Waline',
|
|
41
|
+
}),
|
|
42
|
+
html: this.locale(
|
|
43
|
+
'Please click <a href="{{url}}">{{url}}</a> to login and change your password as soon as possible!',
|
|
44
|
+
{ url: profileUrl }
|
|
45
|
+
),
|
|
41
46
|
});
|
|
42
47
|
|
|
43
48
|
return this.success();
|
package/src/controller/user.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = class extends BaseRest {
|
|
|
21
21
|
!think.isEmpty(resp) &&
|
|
22
22
|
['administrator', 'guest'].includes(resp[0].type)
|
|
23
23
|
) {
|
|
24
|
-
return this.fail('USER_EXIST');
|
|
24
|
+
return this.fail(this.locale('USER_EXIST'));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const count = await this.modelInstance.count();
|
|
@@ -56,21 +56,37 @@ module.exports = class extends BaseRest {
|
|
|
56
56
|
return this.success();
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
try {
|
|
60
|
+
const notify = this.service('notify');
|
|
61
|
+
const apiUrl =
|
|
62
|
+
this.ctx.serverURL +
|
|
63
|
+
'/verification?' +
|
|
64
|
+
qs.stringify({ token, email: data.email });
|
|
65
|
+
|
|
66
|
+
await notify.transporter.sendMail({
|
|
67
|
+
from:
|
|
68
|
+
SENDER_EMAIL && SENDER_NAME
|
|
69
|
+
? `"${SENDER_NAME}" <${SENDER_EMAIL}>`
|
|
70
|
+
: SMTP_USER,
|
|
71
|
+
to: data.email,
|
|
72
|
+
subject: this.locale('[{{name}}] Registration Confirm Mail', {
|
|
73
|
+
name: SITE_NAME || 'Waline',
|
|
74
|
+
}),
|
|
75
|
+
html: this.locale(
|
|
76
|
+
'Please click <a href="{{url}}">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.',
|
|
77
|
+
{ url: apiUrl }
|
|
78
|
+
),
|
|
79
|
+
});
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.log(e);
|
|
82
|
+
|
|
83
|
+
return this.fail(
|
|
84
|
+
this.locale(
|
|
85
|
+
'Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.',
|
|
86
|
+
{ isAdmin: think.isEmpty(count) }
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
74
90
|
|
|
75
91
|
return this.success({ verify: true });
|
|
76
92
|
}
|
|
@@ -13,13 +13,13 @@ module.exports = class extends BaseRest {
|
|
|
13
13
|
const { token, email } = this.get();
|
|
14
14
|
const users = await this.modelInstance.select({ email });
|
|
15
15
|
if (think.isEmpty(users)) {
|
|
16
|
-
return this.fail('USER_NOT_EXIST');
|
|
16
|
+
return this.fail(this.locale('USER_NOT_EXIST'));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const user = users[0];
|
|
20
20
|
const match = user.type.match(/^verify:(\d{4}):(\d+)$/i);
|
|
21
21
|
if (!match) {
|
|
22
|
-
return this.fail('USER_REGISTED');
|
|
22
|
+
return this.fail(this.locale('USER_REGISTED'));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if (token === match[1] && Date.now() < parseInt(match[2])) {
|
|
@@ -27,6 +27,6 @@ module.exports = class extends BaseRest {
|
|
|
27
27
|
return this.redirect('/ui/login');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
return this.fail('TOKEN_EXPIRED');
|
|
30
|
+
return this.fail(this.locale('TOKEN_EXPIRED'));
|
|
31
31
|
}
|
|
32
32
|
};
|
package/src/extend/controller.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const nunjucks = require('nunjucks');
|
|
2
|
+
const locales = require('../locales');
|
|
3
|
+
|
|
1
4
|
module.exports = {
|
|
2
5
|
success(...args) {
|
|
3
6
|
this.ctx.success(...args);
|
|
@@ -7,4 +10,12 @@ module.exports = {
|
|
|
7
10
|
this.ctx.fail(...args);
|
|
8
11
|
return think.prevent();
|
|
9
12
|
},
|
|
13
|
+
locale(message, variables) {
|
|
14
|
+
const { lang } = this.get();
|
|
15
|
+
const locale = locales[(lang || '').toLowerCase()];
|
|
16
|
+
if (locale && locale[message]) {
|
|
17
|
+
message = locale[message];
|
|
18
|
+
}
|
|
19
|
+
return nunjucks.renderString(message, variables);
|
|
20
|
+
},
|
|
10
21
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"import data format not support!": "import data format not support!",
|
|
3
|
+
"USER_EXIST": "USER_EXIST",
|
|
4
|
+
"USER_NOT_EXIST": "USER_NOT_EXIST",
|
|
5
|
+
"USER_REGISTED": "USER_REGISTED",
|
|
6
|
+
"TOKEN_EXPIRED": "TOKEN_EXPIRED",
|
|
7
|
+
"TWO_FACTOR_AUTH_ERROR_DETAIL": "TWO_FACTOR_AUTH_ERROR_DETAIL",
|
|
8
|
+
"[{{name}}] Registration Confirm Mail": "[{{name}}] Registration Confirm Mail",
|
|
9
|
+
"Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.",
|
|
10
|
+
"[{{name}}] Reset Password": "[{{name}}] Reset Password",
|
|
11
|
+
"Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!",
|
|
12
|
+
"Duplicate Content": "Duplicate Content",
|
|
13
|
+
"Comment too fast": "Comment too fast",
|
|
14
|
+
"Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}."
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"import data format not support!": "文件格式不支持",
|
|
3
|
+
"USER_EXIST": "用户已存在",
|
|
4
|
+
"USER_NOT_EXIST": "用户不存在",
|
|
5
|
+
"USER_REGISTED": "用户已注册",
|
|
6
|
+
"TOKEN_EXPIRED": "密钥已过期",
|
|
7
|
+
"TWO_FACTOR_AUTH_ERROR_DETAIL": "二步验证失败",
|
|
8
|
+
"[{{name}}] Registration Confirm Mail": "【{{name}}】注册确认邮件",
|
|
9
|
+
"Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "请点击 <a href=\"{{url}}\">{{url}}</a> 确认注册,链接有效时间为 1 个小时。如果不是你在注册,请忽略这封邮件。",
|
|
10
|
+
"[{{name}}] Reset Password": "【{{name}}】重置密码",
|
|
11
|
+
"Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "请尽快点击链接 <a href=\"{{url}}\">{{url}}</a> 登录并修改你的密码!",
|
|
12
|
+
"Duplicate Content": "发送的内容之前已经发过",
|
|
13
|
+
"Comment too fast": "评论太快啦,请慢点!",
|
|
14
|
+
"Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "注册确认邮件发送失败,请{%- if isAdmin -%}检查一下网站的邮件相关配置{% else %}确认你的邮箱输入无误并联系管理员{%- endif -%}。"
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"import data format not support!": "文件格式不支持",
|
|
3
|
+
"USER_EXIST": "用戶已存在",
|
|
4
|
+
"USER_NOT_EXIST": "用戶不存在",
|
|
5
|
+
"USER_REGISTED": "用戶已註冊",
|
|
6
|
+
"TOKEN_EXPIRED": "密鑰已過期",
|
|
7
|
+
"TWO_FACTOR_AUTH_ERROR_DETAIL": "二步驗證失敗",
|
|
8
|
+
"[{{name}}] Registration Confirm Mail": "『{{name}}』註冊確認郵件",
|
|
9
|
+
"Please click <a href=\"{{url}}\">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.": "請點擊 <a href=\"{{url}}\">{{url}}</a> 確認註冊,鏈接有效時間為 1 個小時。如果不是你在註冊,請忽略這封郵件。",
|
|
10
|
+
"[{{name}}] Reset Password": "『{{name}}』重置密碼",
|
|
11
|
+
"Please click <a href=\"{{url}}\">{{url}}</a> to login and change your password as soon as possible!": "請盡快點擊鏈接 <a href=\"{{url}}\">{{url}}</a> 登錄並修改你的密碼!",
|
|
12
|
+
"Duplicate Content": "發送的內容之前已經發過",
|
|
13
|
+
"Comment too fast": "評論太快啦,請慢點!",
|
|
14
|
+
"Registeration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.": "註冊確認郵件發送失敗,{%- if isAdmin -%}檢查一下網站的郵件相關配置{% else %}確認你的郵箱輸入無誤後聯繫管理員{%- endif -%}。"
|
|
15
|
+
}
|