@waline/vercel 1.29.0 → 1.30.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/dist/src/controller/article.js +1 -4
- package/dist/src/controller/comment.js +7 -28
- package/package.json +1 -1
- package/src/controller/article.js +1 -4
- package/src/controller/comment.js +7 -28
- package/src/controller/db.js +4 -7
- package/src/controller/oauth.js +2 -6
- package/src/controller/token/2fa.js +2 -8
- package/src/controller/token.js +2 -9
- package/src/controller/user/password.js +1 -4
- package/src/controller/user.js +4 -12
- package/src/controller/verification.js +1 -4
- package/src/extend/controller.js +26 -0
- package/src/logic/base.js +1 -4
- package/src/logic/comment.js +2 -8
|
@@ -3,10 +3,7 @@ const BaseRest = require('./rest');
|
|
|
3
3
|
module.exports = class extends BaseRest {
|
|
4
4
|
constructor(ctx) {
|
|
5
5
|
super(ctx);
|
|
6
|
-
this.modelInstance = this.
|
|
7
|
-
`storage/${this.config('storage')}`,
|
|
8
|
-
'Counter'
|
|
9
|
-
);
|
|
6
|
+
this.modelInstance = this.getModel('Counter');
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
async getAction() {
|
|
@@ -68,10 +68,7 @@ async function formatCmt(
|
|
|
68
68
|
module.exports = class extends BaseRest {
|
|
69
69
|
constructor(ctx) {
|
|
70
70
|
super(ctx);
|
|
71
|
-
this.modelInstance = this.
|
|
72
|
-
`storage/${this.config('storage')}`,
|
|
73
|
-
'Comment'
|
|
74
|
-
);
|
|
71
|
+
this.modelInstance = this.getModel('Comment');
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
async getAction() {
|
|
@@ -114,10 +111,7 @@ module.exports = class extends BaseRest {
|
|
|
114
111
|
],
|
|
115
112
|
});
|
|
116
113
|
|
|
117
|
-
const userModel = this.
|
|
118
|
-
`storage/${this.config('storage')}`,
|
|
119
|
-
'Users'
|
|
120
|
-
);
|
|
114
|
+
const userModel = this.getModel('Users');
|
|
121
115
|
const user_ids = Array.from(
|
|
122
116
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
123
117
|
);
|
|
@@ -212,10 +206,7 @@ module.exports = class extends BaseRest {
|
|
|
212
206
|
offset: Math.max((page - 1) * pageSize, 0),
|
|
213
207
|
});
|
|
214
208
|
|
|
215
|
-
const userModel = this.
|
|
216
|
-
`storage/${this.config('storage')}`,
|
|
217
|
-
'Users'
|
|
218
|
-
);
|
|
209
|
+
const userModel = this.getModel('Users');
|
|
219
210
|
const user_ids = Array.from(
|
|
220
211
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
221
212
|
);
|
|
@@ -355,10 +346,7 @@ module.exports = class extends BaseRest {
|
|
|
355
346
|
});
|
|
356
347
|
}
|
|
357
348
|
|
|
358
|
-
const userModel = this.
|
|
359
|
-
`storage/${this.config('storage')}`,
|
|
360
|
-
'Users'
|
|
361
|
-
);
|
|
349
|
+
const userModel = this.getModel('Users');
|
|
362
350
|
const user_ids = Array.from(
|
|
363
351
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
364
352
|
);
|
|
@@ -592,10 +580,7 @@ module.exports = class extends BaseRest {
|
|
|
592
580
|
parentComment = await this.modelInstance.select({ objectId: pid });
|
|
593
581
|
parentComment = parentComment[0];
|
|
594
582
|
if (parentComment.user_id) {
|
|
595
|
-
parentUser = await this.
|
|
596
|
-
`storage/${this.config('storage')}`,
|
|
597
|
-
'Users'
|
|
598
|
-
).select({
|
|
583
|
+
parentUser = await this.getModel('Users').select({
|
|
599
584
|
objectId: parentComment.user_id,
|
|
600
585
|
});
|
|
601
586
|
parentUser = parentUser[0];
|
|
@@ -677,10 +662,7 @@ module.exports = class extends BaseRest {
|
|
|
677
662
|
let cmtUser;
|
|
678
663
|
|
|
679
664
|
if (!think.isEmpty(newData) && newData[0].user_id) {
|
|
680
|
-
cmtUser = await this.
|
|
681
|
-
`storage/${this.config('storage')}`,
|
|
682
|
-
'Users'
|
|
683
|
-
).select({
|
|
665
|
+
cmtUser = await this.getModel('Users').select({
|
|
684
666
|
objectId: newData[0].user_id,
|
|
685
667
|
});
|
|
686
668
|
cmtUser = cmtUser[0];
|
|
@@ -706,10 +688,7 @@ module.exports = class extends BaseRest {
|
|
|
706
688
|
let pUser;
|
|
707
689
|
|
|
708
690
|
if (pComment.user_id) {
|
|
709
|
-
pUser = await this.
|
|
710
|
-
`storage/${this.config('storage')}`,
|
|
711
|
-
'Users'
|
|
712
|
-
).select({
|
|
691
|
+
pUser = await this.getModel('Users').select({
|
|
713
692
|
objectId: pComment.user_id,
|
|
714
693
|
});
|
|
715
694
|
pUser = pUser[0];
|
package/package.json
CHANGED
|
@@ -3,10 +3,7 @@ const BaseRest = require('./rest');
|
|
|
3
3
|
module.exports = class extends BaseRest {
|
|
4
4
|
constructor(ctx) {
|
|
5
5
|
super(ctx);
|
|
6
|
-
this.modelInstance = this.
|
|
7
|
-
`storage/${this.config('storage')}`,
|
|
8
|
-
'Counter'
|
|
9
|
-
);
|
|
6
|
+
this.modelInstance = this.getModel('Counter');
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
async getAction() {
|
|
@@ -75,10 +75,7 @@ async function formatCmt(
|
|
|
75
75
|
module.exports = class extends BaseRest {
|
|
76
76
|
constructor(ctx) {
|
|
77
77
|
super(ctx);
|
|
78
|
-
this.modelInstance = this.
|
|
79
|
-
`storage/${this.config('storage')}`,
|
|
80
|
-
'Comment'
|
|
81
|
-
);
|
|
78
|
+
this.modelInstance = this.getModel('Comment');
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
async getAction() {
|
|
@@ -121,10 +118,7 @@ module.exports = class extends BaseRest {
|
|
|
121
118
|
],
|
|
122
119
|
});
|
|
123
120
|
|
|
124
|
-
const userModel = this.
|
|
125
|
-
`storage/${this.config('storage')}`,
|
|
126
|
-
'Users'
|
|
127
|
-
);
|
|
121
|
+
const userModel = this.getModel('Users');
|
|
128
122
|
const user_ids = Array.from(
|
|
129
123
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
130
124
|
);
|
|
@@ -227,10 +221,7 @@ module.exports = class extends BaseRest {
|
|
|
227
221
|
offset: Math.max((page - 1) * pageSize, 0),
|
|
228
222
|
});
|
|
229
223
|
|
|
230
|
-
const userModel = this.
|
|
231
|
-
`storage/${this.config('storage')}`,
|
|
232
|
-
'Users'
|
|
233
|
-
);
|
|
224
|
+
const userModel = this.getModel('Users');
|
|
234
225
|
const user_ids = Array.from(
|
|
235
226
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
236
227
|
);
|
|
@@ -373,10 +364,7 @@ module.exports = class extends BaseRest {
|
|
|
373
364
|
comments = [...rootComments, ...children];
|
|
374
365
|
}
|
|
375
366
|
|
|
376
|
-
const userModel = this.
|
|
377
|
-
`storage/${this.config('storage')}`,
|
|
378
|
-
'Users'
|
|
379
|
-
);
|
|
367
|
+
const userModel = this.getModel('Users');
|
|
380
368
|
const user_ids = Array.from(
|
|
381
369
|
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
382
370
|
);
|
|
@@ -620,10 +608,7 @@ module.exports = class extends BaseRest {
|
|
|
620
608
|
parentComment = await this.modelInstance.select({ objectId: pid });
|
|
621
609
|
parentComment = parentComment[0];
|
|
622
610
|
if (parentComment.user_id) {
|
|
623
|
-
parentUser = await this.
|
|
624
|
-
`storage/${this.config('storage')}`,
|
|
625
|
-
'Users'
|
|
626
|
-
).select({
|
|
611
|
+
parentUser = await this.getModel('Users').select({
|
|
627
612
|
objectId: parentComment.user_id,
|
|
628
613
|
});
|
|
629
614
|
parentUser = parentUser[0];
|
|
@@ -710,10 +695,7 @@ module.exports = class extends BaseRest {
|
|
|
710
695
|
let cmtUser;
|
|
711
696
|
|
|
712
697
|
if (!think.isEmpty(newData) && newData[0].user_id) {
|
|
713
|
-
cmtUser = await this.
|
|
714
|
-
`storage/${this.config('storage')}`,
|
|
715
|
-
'Users'
|
|
716
|
-
).select({
|
|
698
|
+
cmtUser = await this.getModel('Users').select({
|
|
717
699
|
objectId: newData[0].user_id,
|
|
718
700
|
});
|
|
719
701
|
cmtUser = cmtUser[0];
|
|
@@ -739,10 +721,7 @@ module.exports = class extends BaseRest {
|
|
|
739
721
|
let pUser;
|
|
740
722
|
|
|
741
723
|
if (pComment.user_id) {
|
|
742
|
-
pUser = await this.
|
|
743
|
-
`storage/${this.config('storage')}`,
|
|
744
|
-
'Users'
|
|
745
|
-
).select({
|
|
724
|
+
pUser = await this.getModel('Users').select({
|
|
746
725
|
objectId: pComment.user_id,
|
|
747
726
|
});
|
|
748
727
|
pUser = pUser[0];
|
package/src/controller/db.js
CHANGED
|
@@ -16,8 +16,7 @@ module.exports = class extends BaseRest {
|
|
|
16
16
|
|
|
17
17
|
for (let i = 0; i < exportData.tables.length; i++) {
|
|
18
18
|
const tableName = exportData.tables[i];
|
|
19
|
-
const
|
|
20
|
-
const model = this.service(`storage/${storage}`, tableName);
|
|
19
|
+
const model = this.getModel(tableName);
|
|
21
20
|
|
|
22
21
|
const data = await model.select({});
|
|
23
22
|
|
|
@@ -31,7 +30,7 @@ module.exports = class extends BaseRest {
|
|
|
31
30
|
const { table } = this.get();
|
|
32
31
|
const item = this.post();
|
|
33
32
|
const storage = this.config('storage');
|
|
34
|
-
const model = this.
|
|
33
|
+
const model = this.getModel(table);
|
|
35
34
|
|
|
36
35
|
if (storage === 'leancloud' || storage === 'mysql') {
|
|
37
36
|
item.insertedAt && (item.insertedAt = new Date(item.insertedAt));
|
|
@@ -48,8 +47,7 @@ module.exports = class extends BaseRest {
|
|
|
48
47
|
async putAction() {
|
|
49
48
|
const { table, objectId } = this.get();
|
|
50
49
|
const data = this.post();
|
|
51
|
-
const
|
|
52
|
-
const model = this.service(`storage/${storage}`, table);
|
|
50
|
+
const model = this.getModel(table);
|
|
53
51
|
|
|
54
52
|
delete data.objectId;
|
|
55
53
|
delete data.createdAt;
|
|
@@ -61,8 +59,7 @@ module.exports = class extends BaseRest {
|
|
|
61
59
|
|
|
62
60
|
async deleteAction() {
|
|
63
61
|
const { table } = this.get();
|
|
64
|
-
const
|
|
65
|
-
const model = this.service(`storage/${storage}`, table);
|
|
62
|
+
const model = this.getModel(table);
|
|
66
63
|
|
|
67
64
|
await model.delete({});
|
|
68
65
|
|
package/src/controller/oauth.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
const jwt = require('jsonwebtoken');
|
|
2
2
|
const fetch = require('node-fetch');
|
|
3
|
-
const { PasswordHash } = require('phpass');
|
|
4
3
|
|
|
5
4
|
module.exports = class extends think.Controller {
|
|
6
5
|
constructor(ctx) {
|
|
7
6
|
super(ctx);
|
|
8
|
-
this.modelInstance = this.
|
|
9
|
-
`storage/${this.config('storage')}`,
|
|
10
|
-
'Users'
|
|
11
|
-
);
|
|
7
|
+
this.modelInstance = this.getModel('Users');
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
async indexAction() {
|
|
@@ -109,7 +105,7 @@ module.exports = class extends think.Controller {
|
|
|
109
105
|
url: user.url,
|
|
110
106
|
avatar: user.avatar,
|
|
111
107
|
[type]: user.id,
|
|
112
|
-
password:
|
|
108
|
+
password: this.hashPassword(Math.random()),
|
|
113
109
|
type: think.isEmpty(count) ? 'administrator' : 'guest',
|
|
114
110
|
};
|
|
115
111
|
|
|
@@ -8,10 +8,7 @@ module.exports = class extends BaseRest {
|
|
|
8
8
|
const { email } = this.get();
|
|
9
9
|
|
|
10
10
|
if (think.isEmpty(userInfo) && email) {
|
|
11
|
-
const userModel = this.
|
|
12
|
-
`storage/${this.config('storage')}`,
|
|
13
|
-
'Users'
|
|
14
|
-
);
|
|
11
|
+
const userModel = this.getModel('Users');
|
|
15
12
|
|
|
16
13
|
const user = await userModel.select(
|
|
17
14
|
{ email },
|
|
@@ -54,10 +51,7 @@ module.exports = class extends BaseRest {
|
|
|
54
51
|
return this.fail(this.locale('TWO_FACTOR_AUTH_ERROR_DETAIL'));
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
const userModel = this.
|
|
58
|
-
`storage/${this.config('storage')}`,
|
|
59
|
-
'Users'
|
|
60
|
-
);
|
|
54
|
+
const userModel = this.getModel('Users');
|
|
61
55
|
const { objectId } = this.ctx.state.userInfo;
|
|
62
56
|
|
|
63
57
|
await userModel.update({ ['2fa']: data.secret }, { objectId });
|
package/src/controller/token.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const jwt = require('jsonwebtoken');
|
|
2
|
-
const { PasswordHash } = require('phpass');
|
|
3
2
|
const speakeasy = require('speakeasy');
|
|
4
3
|
const helper = require('think-helper');
|
|
5
4
|
|
|
@@ -8,10 +7,7 @@ const BaseRest = require('./rest');
|
|
|
8
7
|
module.exports = class extends BaseRest {
|
|
9
8
|
constructor(...args) {
|
|
10
9
|
super(...args);
|
|
11
|
-
this.modelInstance = this.
|
|
12
|
-
`storage/${this.config('storage')}`,
|
|
13
|
-
'Users'
|
|
14
|
-
);
|
|
10
|
+
this.modelInstance = this.getModel('Users');
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
getAction() {
|
|
@@ -26,10 +22,7 @@ module.exports = class extends BaseRest {
|
|
|
26
22
|
return this.fail();
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
const checkPassword =
|
|
30
|
-
password,
|
|
31
|
-
user[0].password
|
|
32
|
-
);
|
|
25
|
+
const checkPassword = this.checkPassword(password, user[0].password);
|
|
33
26
|
|
|
34
27
|
if (!checkPassword) {
|
|
35
28
|
return this.fail();
|
|
@@ -19,10 +19,7 @@ module.exports = class extends BaseRest {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const { email } = this.post();
|
|
22
|
-
const userModel = this.
|
|
23
|
-
`storage/${this.config('storage')}`,
|
|
24
|
-
'Users'
|
|
25
|
-
);
|
|
22
|
+
const userModel = this.getModel('Users');
|
|
26
23
|
const user = await userModel.select({ email });
|
|
27
24
|
|
|
28
25
|
if (think.isEmpty(user)) {
|
package/src/controller/user.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
const { PasswordHash } = require('phpass');
|
|
2
|
-
|
|
3
1
|
const BaseRest = require('./rest');
|
|
4
2
|
|
|
5
3
|
module.exports = class extends BaseRest {
|
|
6
4
|
constructor(...args) {
|
|
7
5
|
super(...args);
|
|
8
|
-
this.modelInstance = this.
|
|
9
|
-
`storage/${this.config('storage')}`,
|
|
10
|
-
'Users'
|
|
11
|
-
);
|
|
6
|
+
this.modelInstance = this.getModel('Users');
|
|
12
7
|
}
|
|
13
8
|
|
|
14
9
|
async getAction() {
|
|
@@ -81,7 +76,7 @@ module.exports = class extends BaseRest {
|
|
|
81
76
|
? `verify:${token}:${Date.now() + 1 * 60 * 60 * 1000}`
|
|
82
77
|
: 'guest';
|
|
83
78
|
|
|
84
|
-
data.password =
|
|
79
|
+
data.password = this.hashPassword(data.password);
|
|
85
80
|
data.type = think.isEmpty(count) ? 'administrator' : normalType;
|
|
86
81
|
|
|
87
82
|
if (think.isEmpty(resp)) {
|
|
@@ -157,7 +152,7 @@ module.exports = class extends BaseRest {
|
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
if (password) {
|
|
160
|
-
updateData.password =
|
|
155
|
+
updateData.password = this.hashPassword(password);
|
|
161
156
|
}
|
|
162
157
|
|
|
163
158
|
if (think.isString(twoFactorAuth)) {
|
|
@@ -187,10 +182,7 @@ module.exports = class extends BaseRest {
|
|
|
187
182
|
|
|
188
183
|
async getUsersListByCount() {
|
|
189
184
|
const { pageSize } = this.get();
|
|
190
|
-
const commentModel = this.
|
|
191
|
-
`storage/${this.config('storage')}`,
|
|
192
|
-
'Comment'
|
|
193
|
-
);
|
|
185
|
+
const commentModel = this.getModel('Comment');
|
|
194
186
|
const counts = await commentModel.count(
|
|
195
187
|
{
|
|
196
188
|
status: ['NOT IN', ['waiting', 'spam']],
|
|
@@ -3,10 +3,7 @@ const BaseRest = require('./rest');
|
|
|
3
3
|
module.exports = class extends BaseRest {
|
|
4
4
|
constructor(...args) {
|
|
5
5
|
super(...args);
|
|
6
|
-
this.modelInstance = this.
|
|
7
|
-
`storage/${this.config('storage')}`,
|
|
8
|
-
'Users'
|
|
9
|
-
);
|
|
6
|
+
this.modelInstance = this.getModel('Users');
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
async getAction() {
|
package/src/extend/controller.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const nunjucks = require('nunjucks');
|
|
2
|
+
const { PasswordHash } = require('phpass');
|
|
2
3
|
|
|
3
4
|
const locales = require('../locales');
|
|
4
5
|
|
|
@@ -26,4 +27,29 @@ module.exports = {
|
|
|
26
27
|
|
|
27
28
|
return nunjucks.renderString(message, variables);
|
|
28
29
|
},
|
|
30
|
+
getModel(modelName) {
|
|
31
|
+
const { storage, model } = this.config();
|
|
32
|
+
|
|
33
|
+
if (typeof model === 'function') {
|
|
34
|
+
const modelInstance = model(modelName, this);
|
|
35
|
+
|
|
36
|
+
if (modelInstance) {
|
|
37
|
+
return modelInstance;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this.service(`storage/${storage}`, modelName);
|
|
42
|
+
},
|
|
43
|
+
hashPassword(password) {
|
|
44
|
+
const PwdHash = this.config('encryptPassword') || PasswordHash;
|
|
45
|
+
const pwdHash = new PwdHash();
|
|
46
|
+
|
|
47
|
+
return pwdHash.hashPassword(password);
|
|
48
|
+
},
|
|
49
|
+
checkPassword(password, storeHash) {
|
|
50
|
+
const PwdHash = this.config('encryptPassword') || PasswordHash;
|
|
51
|
+
const pwdHash = new PwdHash();
|
|
52
|
+
|
|
53
|
+
return pwdHash.checkPassword(password, storeHash);
|
|
54
|
+
},
|
|
29
55
|
};
|
package/src/logic/base.js
CHANGED
|
@@ -8,10 +8,7 @@ const helper = require('think-helper');
|
|
|
8
8
|
module.exports = class extends think.Logic {
|
|
9
9
|
constructor(...args) {
|
|
10
10
|
super(...args);
|
|
11
|
-
this.modelInstance = this.
|
|
12
|
-
`storage/${this.config('storage')}`,
|
|
13
|
-
'Users'
|
|
14
|
-
);
|
|
11
|
+
this.modelInstance = this.getModel('Users');
|
|
15
12
|
this.resource = this.getResource();
|
|
16
13
|
this.id = this.getId();
|
|
17
14
|
}
|
package/src/logic/comment.js
CHANGED
|
@@ -262,10 +262,7 @@ module.exports = class extends Base {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
// 3. comment author modify comment content
|
|
265
|
-
const modelInstance = this.
|
|
266
|
-
`storage/${this.config('storage')}`,
|
|
267
|
-
'Comment'
|
|
268
|
-
);
|
|
265
|
+
const modelInstance = this.getModel('Comment');
|
|
269
266
|
const commentData = await modelInstance.select({
|
|
270
267
|
user_id: userInfo.objectId,
|
|
271
268
|
objectId: this.id,
|
|
@@ -299,10 +296,7 @@ module.exports = class extends Base {
|
|
|
299
296
|
return;
|
|
300
297
|
}
|
|
301
298
|
|
|
302
|
-
const modelInstance = this.
|
|
303
|
-
`storage/${this.config('storage')}`,
|
|
304
|
-
'Comment'
|
|
305
|
-
);
|
|
299
|
+
const modelInstance = this.getModel('Comment');
|
|
306
300
|
const commentData = await modelInstance.select({
|
|
307
301
|
user_id: userInfo.objectId,
|
|
308
302
|
objectId: this.id,
|