@waline/vercel 1.2.2 → 1.2.6
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 +5 -5
- package/src/controller/comment.js +8 -8
- package/src/controller/index.js +1 -0
- package/src/logic/base.js +6 -2
- package/src/service/avatar.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/vercel",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "vercel server for waline comment system",
|
|
5
5
|
"repository": "https://github.com/walinejs/waline",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"deta": "^1.0.1",
|
|
13
13
|
"dompurify": "^2.3.3",
|
|
14
14
|
"fast-csv": "^4.3.6",
|
|
15
|
-
"jsdom": "^
|
|
15
|
+
"jsdom": "^18.0.0",
|
|
16
16
|
"jsonwebtoken": "^8.5.1",
|
|
17
|
-
"katex": "^0.13.
|
|
17
|
+
"katex": "^0.13.23",
|
|
18
18
|
"leancloud-storage": "^4.12.0",
|
|
19
19
|
"markdown-it": "^12.2.0",
|
|
20
20
|
"markdown-it-emoji": "^2.0.0",
|
|
21
21
|
"markdown-it-sub": "^1.0.0",
|
|
22
22
|
"markdown-it-sup": "^1.0.0",
|
|
23
23
|
"mathjax-full": "^3.2.0",
|
|
24
|
-
"nodemailer": "^6.
|
|
24
|
+
"nodemailer": "^6.7.0",
|
|
25
25
|
"nunjucks": "^3.2.3",
|
|
26
26
|
"phpass": "^0.1.1",
|
|
27
27
|
"prismjs": "^1.25.0",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"think-mongo": "^2.1.2",
|
|
36
36
|
"think-router-rest": "^1.0.5",
|
|
37
37
|
"thinkjs": "^3.2.14",
|
|
38
|
-
"ua-parser-js": "^0.7.
|
|
38
|
+
"ua-parser-js": "^0.7.31"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -19,27 +19,26 @@ async function formatCmt(
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const user = users.find(({ objectId }) => user_id === objectId);
|
|
22
|
-
if (user) {
|
|
22
|
+
if (!think.isEmpty(user)) {
|
|
23
23
|
comment.nick = user.display_name;
|
|
24
24
|
comment.mail = user.email;
|
|
25
25
|
comment.link = user.url;
|
|
26
26
|
comment.type = user.type;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
comment.mail = helper.md5(
|
|
30
|
-
comment.mail ? comment.mail.toLowerCase() : comment.mail
|
|
31
|
-
);
|
|
32
|
-
|
|
33
29
|
const avatarUrl =
|
|
34
30
|
user && user.avatar
|
|
35
31
|
? user.avatar
|
|
36
|
-
:
|
|
37
|
-
|
|
32
|
+
: await think.service('avatar').stringify(comment);
|
|
38
33
|
comment.avatar =
|
|
39
34
|
avatarProxy && !avatarUrl.includes(avatarProxy)
|
|
40
35
|
? avatarProxy + '?url=' + encodeURIComponent(avatarUrl)
|
|
41
36
|
: avatarUrl;
|
|
42
37
|
|
|
38
|
+
comment.mail = helper.md5(
|
|
39
|
+
comment.mail ? comment.mail.toLowerCase() : comment.mail
|
|
40
|
+
);
|
|
41
|
+
|
|
43
42
|
return comment;
|
|
44
43
|
}
|
|
45
44
|
|
|
@@ -71,6 +70,7 @@ module.exports = class extends BaseRest {
|
|
|
71
70
|
'link',
|
|
72
71
|
'mail',
|
|
73
72
|
'nick',
|
|
73
|
+
'url',
|
|
74
74
|
'pid',
|
|
75
75
|
'rid',
|
|
76
76
|
'ua',
|
|
@@ -257,7 +257,7 @@ module.exports = class extends BaseRest {
|
|
|
257
257
|
if (pid) {
|
|
258
258
|
data.comment = data.comment.replace(
|
|
259
259
|
'<p>',
|
|
260
|
-
`<p><a class="at" href="#${pid}">@${at}</a
|
|
260
|
+
`<p><a class="at" href="#${pid}">@${at}</a>: `
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
|
package/src/controller/index.js
CHANGED
|
@@ -22,6 +22,7 @@ module.exports = class extends think.Controller {
|
|
|
22
22
|
const waline = new Waline({
|
|
23
23
|
el: '#waline',
|
|
24
24
|
path: '/',
|
|
25
|
+
lang: new URLSearchParams(location.search.slice(1)).get('lng'),
|
|
25
26
|
serverURL: location.protocol + '//' + location.host + location.pathname.replace(/\\/+$/, '')
|
|
26
27
|
});
|
|
27
28
|
</script>
|
package/src/logic/base.js
CHANGED
|
@@ -50,16 +50,20 @@ module.exports = class extends think.Logic {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const userInfo = user[0];
|
|
53
|
-
userInfo.mailMd5 = helper.md5(userInfo.email);
|
|
54
53
|
|
|
55
54
|
let avatarUrl = userInfo.avatar
|
|
56
55
|
? userInfo.avatar
|
|
57
|
-
:
|
|
56
|
+
: await think.service('avatar').stringify({
|
|
57
|
+
mail: userInfo.email,
|
|
58
|
+
nick: userInfo.display_name,
|
|
59
|
+
link: userInfo.url,
|
|
60
|
+
});
|
|
58
61
|
const { avatarProxy } = think.config();
|
|
59
62
|
if (avatarProxy) {
|
|
60
63
|
avatarUrl = avatarProxy + '?url=' + encodeURIComponent(avatarUrl);
|
|
61
64
|
}
|
|
62
65
|
userInfo.avatar = avatarUrl;
|
|
66
|
+
userInfo.mailMd5 = helper.md5(userInfo.email);
|
|
63
67
|
this.ctx.state.userInfo = userInfo;
|
|
64
68
|
}
|
|
65
69
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const nunjucks = require('nunjucks');
|
|
2
|
+
const helper = require('think-helper');
|
|
3
|
+
const { GRAVATAR_STR } = process.env;
|
|
4
|
+
|
|
5
|
+
const env = new nunjucks.Environment();
|
|
6
|
+
env.addFilter('md5', (str) => helper.md5(str));
|
|
7
|
+
|
|
8
|
+
module.exports = class extends think.Service {
|
|
9
|
+
async stringify(comment) {
|
|
10
|
+
const fn = think.config('avatarUrl');
|
|
11
|
+
if (think.isFunction(fn)) {
|
|
12
|
+
const ret = await fn(comment);
|
|
13
|
+
if (think.isString(ret) && ret) {
|
|
14
|
+
return ret;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const gravatarStr =
|
|
19
|
+
GRAVATAR_STR || 'https://seccdn.libravatar.org/avatar/{{mail|md5}}';
|
|
20
|
+
return env.renderString(gravatarStr, comment);
|
|
21
|
+
}
|
|
22
|
+
};
|