@waline/vercel 1.31.14 → 1.32.1
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/index.js +2 -1
- package/package.json +7 -7
- package/src/controller/article.js +20 -6
- package/src/controller/comment.js +8 -3
- package/src/controller/db.js +10 -16
- package/src/extend/controller.js +18 -8
- package/src/service/markdown/index.js +2 -8
- package/src/service/notify.js +7 -7
- package/src/service/storage/base.js +0 -1
- package/src/service/storage/deta.js +1 -1
- package/vanilla.js +1 -1
package/index.js
CHANGED
|
@@ -22,7 +22,8 @@ module.exports = function (configParams = {}) {
|
|
|
22
22
|
|
|
23
23
|
return function (req, res) {
|
|
24
24
|
for (const k in config) {
|
|
25
|
-
|
|
25
|
+
// fix https://github.com/walinejs/waline/issues/2649 with alias model config name
|
|
26
|
+
think.config(k === 'model' ? 'customModel' : k, config[k]);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
return think
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/vercel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.1",
|
|
4
4
|
"description": "vercel server for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"waline",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"author": "lizheming <i@imnerd.org>",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@cloudbase/node-sdk": "^2.
|
|
18
|
+
"@cloudbase/node-sdk": "^3.2.0",
|
|
19
19
|
"@koa/cors": "^5.0.0",
|
|
20
20
|
"@mdit/plugin-katex": "0.8.0",
|
|
21
21
|
"@mdit/plugin-mathjax": "0.4.8",
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
"@mdit/plugin-sup": "0.8.0",
|
|
24
24
|
"akismet": "^2.0.7",
|
|
25
25
|
"deta": "^2.0.0",
|
|
26
|
-
"dompurify": "^3.1.
|
|
26
|
+
"dompurify": "^3.1.6",
|
|
27
27
|
"dy-node-ip2region": "^1.0.1",
|
|
28
28
|
"fast-csv": "^5.0.1",
|
|
29
29
|
"form-data": "^4.0.0",
|
|
30
|
-
"jsdom": "^24.
|
|
30
|
+
"jsdom": "^24.1.1",
|
|
31
31
|
"jsonwebtoken": "^9.0.2",
|
|
32
|
-
"katex": "^0.16.
|
|
32
|
+
"katex": "^0.16.11",
|
|
33
33
|
"koa-compose": "^4.1.0",
|
|
34
34
|
"leancloud-storage": "^4.15.2",
|
|
35
35
|
"markdown-it": "^14.1.0",
|
|
36
36
|
"markdown-it-emoji": "^3.0.0",
|
|
37
37
|
"mathjax-full": "^3.2.2",
|
|
38
38
|
"node-fetch": "^2.7.0",
|
|
39
|
-
"nodemailer": "^6.9.
|
|
39
|
+
"nodemailer": "^6.9.14",
|
|
40
40
|
"nunjucks": "^3.2.4",
|
|
41
41
|
"phpass": "^0.1.1",
|
|
42
42
|
"prismjs": "^1.29.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"think-mongo": "^2.2.1",
|
|
52
52
|
"think-router-rest": "^1.0.5",
|
|
53
53
|
"thinkjs": "^3.2.15",
|
|
54
|
-
"ua-parser-js": "^1.0.
|
|
54
|
+
"ua-parser-js": "^1.0.38"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=16"
|
|
@@ -18,14 +18,28 @@ module.exports = class extends BaseRest {
|
|
|
18
18
|
const resp = await this.modelInstance.select({ url: ['IN', path] });
|
|
19
19
|
|
|
20
20
|
if (think.isEmpty(resp)) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const counters = new Array(path.length).fill(
|
|
22
|
+
type.length === 1 && deprecated
|
|
23
|
+
? 0
|
|
24
|
+
: type.reduce((o, field) => {
|
|
25
|
+
o[field] = 0;
|
|
26
|
+
|
|
27
|
+
return o;
|
|
28
|
+
}, {}),
|
|
29
|
+
);
|
|
26
30
|
|
|
31
|
+
// - deprecated:
|
|
32
|
+
// - single path and single type: 0
|
|
33
|
+
// - single path and multiple type: {[type]: 0}
|
|
34
|
+
// - multiple path and single type: [0, 0]
|
|
35
|
+
// - multiple path and multiple type: [{[type]: 0},{[type]: 0}]
|
|
36
|
+
// - latest
|
|
37
|
+
// - single path and single type: [{[type]: 0}]
|
|
38
|
+
// - single path and multiple type: [{[type]: 0}]
|
|
39
|
+
// - multiple path and single type: [{[type]: 0}]
|
|
40
|
+
// - multiple path and multiple type: [{[type]: 0}]
|
|
27
41
|
return this.jsonOrSuccess(
|
|
28
|
-
|
|
42
|
+
path.length === 1 && deprecated ? counters[0] : counters,
|
|
29
43
|
);
|
|
30
44
|
}
|
|
31
45
|
|
|
@@ -575,10 +575,15 @@ module.exports = class extends BaseRest {
|
|
|
575
575
|
cmt.children.forEach((c) => {
|
|
576
576
|
const parent = childCommentsMap.get(c.pid);
|
|
577
577
|
|
|
578
|
+
// fix https://github.com/walinejs/waline/issues/2518 avoid some abnormal comment data
|
|
579
|
+
if (!parent) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
|
|
578
583
|
c.reply_user = {
|
|
579
|
-
nick: parent
|
|
580
|
-
link: parent
|
|
581
|
-
avatar: parent
|
|
584
|
+
nick: parent?.nick,
|
|
585
|
+
link: parent?.link,
|
|
586
|
+
avatar: parent?.avatar,
|
|
582
587
|
};
|
|
583
588
|
});
|
|
584
589
|
|
package/src/controller/db.js
CHANGED
|
@@ -32,27 +32,21 @@ module.exports = class extends BaseRest {
|
|
|
32
32
|
const model = this.getModel(table);
|
|
33
33
|
|
|
34
34
|
if (storage === 'leancloud' || storage === 'mysql') {
|
|
35
|
-
item.insertedAt
|
|
36
|
-
item.createdAt
|
|
37
|
-
item.updatedAt
|
|
35
|
+
if (item.insertedAt) item.insertedAt = new Date(item.insertedAt);
|
|
36
|
+
if (item.createdAt) item.createdAt = new Date(item.createdAt);
|
|
37
|
+
if (item.updatedAt) item.updatedAt = new Date(item.updatedAt);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (storage === 'mysql') {
|
|
41
|
-
item.insertedAt
|
|
42
|
-
|
|
41
|
+
if (item.insertedAt)
|
|
42
|
+
item.insertedAt = think.datetime(
|
|
43
43
|
item.insertedAt,
|
|
44
44
|
'YYYY-MM-DD HH:mm:ss',
|
|
45
|
-
)
|
|
46
|
-
item.createdAt
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
));
|
|
51
|
-
item.updatedAt &&
|
|
52
|
-
(item.updatedAt = think.datetime(
|
|
53
|
-
item.updatedAt,
|
|
54
|
-
'YYYY-MM-DD HH:mm:ss',
|
|
55
|
-
));
|
|
45
|
+
);
|
|
46
|
+
if (item.createdAt)
|
|
47
|
+
item.createdAt = think.datetime(item.createdAt, 'YYYY-MM-DD HH:mm:ss');
|
|
48
|
+
if (item.updatedAt)
|
|
49
|
+
item.updatedAt = think.datetime(item.updatedAt, 'YYYY-MM-DD HH:mm:ss');
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
delete item.objectId;
|
package/src/extend/controller.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const nunjucks = require('nunjucks');
|
|
2
2
|
const { PasswordHash } = require('phpass');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const defaultLocales = require('../locales/index.js');
|
|
5
|
+
|
|
6
|
+
const defaultLang = 'en-us';
|
|
5
7
|
|
|
6
8
|
module.exports = {
|
|
7
9
|
success(...args) {
|
|
@@ -18,20 +20,28 @@ module.exports = {
|
|
|
18
20
|
return this[this.ctx.state.deprecated ? 'json' : 'success'](...args);
|
|
19
21
|
},
|
|
20
22
|
locale(message, variables) {
|
|
21
|
-
const {
|
|
22
|
-
const
|
|
23
|
+
const { userLang } = this.get();
|
|
24
|
+
const lang = (userLang || defaultLang).toLowerCase();
|
|
25
|
+
|
|
26
|
+
const customLocales = this.config('locales');
|
|
27
|
+
const locales = customLocales || defaultLocales;
|
|
28
|
+
|
|
29
|
+
const localMessage =
|
|
30
|
+
locales?.[lang]?.[message] ||
|
|
31
|
+
defaultLocales?.[lang]?.[message] ||
|
|
32
|
+
defaultLocales[defaultLang][message];
|
|
23
33
|
|
|
24
|
-
if (
|
|
25
|
-
message =
|
|
34
|
+
if (localMessage) {
|
|
35
|
+
message = localMessage;
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
return nunjucks.renderString(message, variables);
|
|
29
39
|
},
|
|
30
40
|
getModel(modelName) {
|
|
31
|
-
const { storage,
|
|
41
|
+
const { storage, customModel } = this.config();
|
|
32
42
|
|
|
33
|
-
if (typeof
|
|
34
|
-
const modelInstance =
|
|
43
|
+
if (typeof customModel === 'function') {
|
|
44
|
+
const modelInstance = customModel(modelName, this);
|
|
35
45
|
|
|
36
46
|
if (modelInstance) {
|
|
37
47
|
return modelInstance;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
const { katex: katexPlugin } = require('@mdit/plugin-katex');
|
|
2
|
-
const {
|
|
3
|
-
createMathjaxInstance,
|
|
4
|
-
mathjax: mathjaxPlugin,
|
|
5
|
-
} = require('@mdit/plugin-mathjax');
|
|
6
2
|
const { sub: subPlugin } = require('@mdit/plugin-sub');
|
|
7
3
|
const { sup: supPlugin } = require('@mdit/plugin-sup');
|
|
8
4
|
const MarkdownIt = require('markdown-it');
|
|
9
5
|
const emojiPlugin = require('markdown-it-emoji');
|
|
10
6
|
|
|
11
7
|
const { resolveHighlighter } = require('./highlight.js');
|
|
8
|
+
const { mathjaxPlugin } = require('./mathjax.js');
|
|
12
9
|
const { sanitize } = require('./xss.js');
|
|
13
10
|
|
|
14
11
|
const getMarkdownParser = () => {
|
|
@@ -58,10 +55,7 @@ const getMarkdownParser = () => {
|
|
|
58
55
|
output: 'mathml',
|
|
59
56
|
});
|
|
60
57
|
} else if (tex !== false) {
|
|
61
|
-
markdownIt.use(
|
|
62
|
-
mathjaxPlugin,
|
|
63
|
-
createMathjaxInstance({ ...mathjax, output: 'svg' }),
|
|
64
|
-
);
|
|
58
|
+
markdownIt.use(mathjaxPlugin, mathjax);
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
return (content) => sanitize(markdownIt.render(content));
|
package/src/service/notify.js
CHANGED
|
@@ -346,13 +346,13 @@ module.exports = class extends think.Service {
|
|
|
346
346
|
|
|
347
347
|
const form = new FormData();
|
|
348
348
|
|
|
349
|
-
topic
|
|
350
|
-
template
|
|
351
|
-
channel
|
|
352
|
-
webhook
|
|
353
|
-
callbackUrl
|
|
354
|
-
title
|
|
355
|
-
content
|
|
349
|
+
if (topic) form.append('topic', topic);
|
|
350
|
+
if (template) form.append('template', template);
|
|
351
|
+
if (channel) form.append('channel', channel);
|
|
352
|
+
if (webhook) form.append('webhook', webhook);
|
|
353
|
+
if (callbackUrl) form.append('callbackUrl', callbackUrl);
|
|
354
|
+
if (title) form.append('title', title);
|
|
355
|
+
if (content) form.append('content', content);
|
|
356
356
|
|
|
357
357
|
return fetch(`http://www.pushplus.plus/send/${PUSH_PLUS_KEY}`, {
|
|
358
358
|
method: 'POST',
|