@waline/vercel 1.15.3 → 1.16.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 +2 -1
- package/src/config/config.js +2 -0
- package/src/controller/comment.js +8 -1
- package/src/extend/think.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/vercel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "vercel server for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"waline",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"akismet": "^2.0.7",
|
|
21
21
|
"deta": "^1.1.0",
|
|
22
22
|
"dompurify": "^2.3.6",
|
|
23
|
+
"dy-node-ip2region": "^1.0.1",
|
|
23
24
|
"fast-csv": "^4.3.6",
|
|
24
25
|
"jsdom": "^19.0.0",
|
|
25
26
|
"jsonwebtoken": "^8.5.1",
|
package/src/config/config.js
CHANGED
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
TCB_KEY,
|
|
15
15
|
SECURE_DOMAINS,
|
|
16
16
|
DISABLE_USERAGENT,
|
|
17
|
+
DISABLE_REGION,
|
|
17
18
|
AVATAR_PROXY,
|
|
18
19
|
GITHUB_TOKEN,
|
|
19
20
|
DETA_PROJECT_KEY,
|
|
@@ -106,6 +107,7 @@ module.exports = {
|
|
|
106
107
|
disallowIPList: [],
|
|
107
108
|
secureDomains: SECURE_DOMAINS ? SECURE_DOMAINS.split(/\s*,\s*/) : undefined,
|
|
108
109
|
disableUserAgent: DISABLE_USERAGENT && !isFalse(DISABLE_USERAGENT),
|
|
110
|
+
disableReigon: DISABLE_REGION && !isFalse(DISABLE_REGION),
|
|
109
111
|
levels:
|
|
110
112
|
!LEVELS || isFalse(LEVELS)
|
|
111
113
|
? false
|
|
@@ -5,7 +5,7 @@ const { getMarkdownParser } = require('../service/markdown');
|
|
|
5
5
|
|
|
6
6
|
const markdownParser = getMarkdownParser();
|
|
7
7
|
async function formatCmt(
|
|
8
|
-
{ ua, user_id, ...comment },
|
|
8
|
+
{ ua, user_id, ip, ...comment },
|
|
9
9
|
users = [],
|
|
10
10
|
{ avatarProxy },
|
|
11
11
|
loginUser
|
|
@@ -41,8 +41,13 @@ async function formatCmt(
|
|
|
41
41
|
delete comment.mail;
|
|
42
42
|
} else {
|
|
43
43
|
comment.orig = comment.comment;
|
|
44
|
+
comment.ip = ip;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
// administrator can always show region
|
|
48
|
+
if (isAdmin || !think.config('disableRegion')) {
|
|
49
|
+
comment.addr = await think.ip2region(ip, { depth: isAdmin ? 3 : 1 });
|
|
50
|
+
}
|
|
46
51
|
comment.comment = markdownParser(comment.comment);
|
|
47
52
|
return comment;
|
|
48
53
|
}
|
|
@@ -88,6 +93,7 @@ module.exports = class extends BaseRest {
|
|
|
88
93
|
'pid',
|
|
89
94
|
'rid',
|
|
90
95
|
'ua',
|
|
96
|
+
'ip',
|
|
91
97
|
'user_id',
|
|
92
98
|
'sticky',
|
|
93
99
|
],
|
|
@@ -235,6 +241,7 @@ module.exports = class extends BaseRest {
|
|
|
235
241
|
'pid',
|
|
236
242
|
'rid',
|
|
237
243
|
'ua',
|
|
244
|
+
'ip',
|
|
238
245
|
'user_id',
|
|
239
246
|
'sticky',
|
|
240
247
|
],
|
package/src/extend/think.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
const ip2region = require('dy-node-ip2region');
|
|
2
|
+
const helper = require('think-helper');
|
|
1
3
|
const preventMessage = 'PREVENT_NEXT_PROCESS';
|
|
2
4
|
|
|
5
|
+
const regionSearch = ip2region.create();
|
|
6
|
+
|
|
3
7
|
module.exports = {
|
|
4
8
|
prevent() {
|
|
5
9
|
throw new Error(preventMessage);
|
|
@@ -46,4 +50,18 @@ module.exports = {
|
|
|
46
50
|
}
|
|
47
51
|
});
|
|
48
52
|
},
|
|
53
|
+
async ip2region(ip, { depth = 1 }) {
|
|
54
|
+
if (!ip) return '';
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const search = helper.promisify(regionSearch.btreeSearch, regionSearch);
|
|
58
|
+
const { region } = await search(ip);
|
|
59
|
+
const [,, province, city, isp] = region.split('|');
|
|
60
|
+
const address = Array.from(new Set([province, city, isp]));
|
|
61
|
+
return address.slice(0, depth).join(' ');
|
|
62
|
+
} catch(e) {
|
|
63
|
+
console.log(e);
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
49
67
|
};
|