@waline/vercel 1.23.4 → 1.24.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/controller/db.js +3 -0
- package/src/controller/user.js +121 -1
- package/src/logic/user.js +27 -1
- package/src/service/storage/leancloud.js +35 -0
package/package.json
CHANGED
package/src/controller/db.js
CHANGED
|
@@ -51,6 +51,9 @@ module.exports = class extends BaseRest {
|
|
|
51
51
|
const storage = this.config('storage');
|
|
52
52
|
const model = this.service(`storage/${storage}`, table);
|
|
53
53
|
|
|
54
|
+
delete data.objectId;
|
|
55
|
+
delete data.createdAt;
|
|
56
|
+
delete data.updatedAt;
|
|
54
57
|
await model.update(data, { objectId });
|
|
55
58
|
|
|
56
59
|
return this.success();
|
package/src/controller/user.js
CHANGED
|
@@ -11,7 +11,24 @@ module.exports = class extends BaseRest {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async getAction() {
|
|
14
|
-
const { page, pageSize } = this.get();
|
|
14
|
+
const { page, pageSize, email } = this.get();
|
|
15
|
+
const { userInfo } = this.ctx.state;
|
|
16
|
+
|
|
17
|
+
if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
|
|
18
|
+
const users = await this.getUsersListByCount();
|
|
19
|
+
|
|
20
|
+
return this.success(users);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (email) {
|
|
24
|
+
const user = await this.modelInstance.select({ email });
|
|
25
|
+
|
|
26
|
+
if (think.isEmpty(user)) {
|
|
27
|
+
return this.success();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return this.success(user[0]);
|
|
31
|
+
}
|
|
15
32
|
|
|
16
33
|
const count = await this.modelInstance.count({});
|
|
17
34
|
const users = await this.modelInstance.select(
|
|
@@ -166,4 +183,107 @@ module.exports = class extends BaseRest {
|
|
|
166
183
|
|
|
167
184
|
return this.success();
|
|
168
185
|
}
|
|
186
|
+
|
|
187
|
+
async getUsersListByCount() {
|
|
188
|
+
const { pageSize } = this.get();
|
|
189
|
+
const commentModel = this.service(
|
|
190
|
+
`storage/${this.config('storage')}`,
|
|
191
|
+
'Comment'
|
|
192
|
+
);
|
|
193
|
+
const counts = await commentModel.count(
|
|
194
|
+
{
|
|
195
|
+
status: ['NOT IN', ['waiting', 'spam']],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
group: ['user_id', 'mail'],
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
counts.sort((a, b) => b.count - a.count);
|
|
203
|
+
counts.length = Math.min(pageSize, counts.length);
|
|
204
|
+
|
|
205
|
+
const userIds = counts
|
|
206
|
+
.filter(({ user_id }) => user_id)
|
|
207
|
+
.map(({ user_id }) => user_id);
|
|
208
|
+
|
|
209
|
+
let usersMap = {};
|
|
210
|
+
|
|
211
|
+
if (userIds.length) {
|
|
212
|
+
const users = await this.modelInstance.select({
|
|
213
|
+
objectId: ['IN', userIds],
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
for (let i = 0; i < users.length; i++) {
|
|
217
|
+
usersMap[users[i].objectId] = users;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const users = [];
|
|
222
|
+
const { avatarProxy } = this.config();
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < counts.length; i++) {
|
|
225
|
+
const count = counts[i];
|
|
226
|
+
const user = {
|
|
227
|
+
count: count.count,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
if (think.isArray(this.config('levels'))) {
|
|
231
|
+
let level = 0;
|
|
232
|
+
|
|
233
|
+
if (user.count) {
|
|
234
|
+
const _level = think.findLastIndex(
|
|
235
|
+
this.config('levels'),
|
|
236
|
+
(l) => l <= user.count
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
if (_level !== -1) {
|
|
240
|
+
level = _level;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
user.level = level;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (count.user_id && users[count.user_id]) {
|
|
247
|
+
const {
|
|
248
|
+
display_name: nick,
|
|
249
|
+
url: link,
|
|
250
|
+
avatar: avatarUrl,
|
|
251
|
+
label,
|
|
252
|
+
} = users[count.user_id];
|
|
253
|
+
const avatar =
|
|
254
|
+
avatarProxy && !avatarUrl.includes(avatarProxy)
|
|
255
|
+
? avatarProxy + '?url=' + encodeURIComponent(avatarUrl)
|
|
256
|
+
: avatarUrl;
|
|
257
|
+
|
|
258
|
+
Object.assign(user, { nick, link, avatar, label });
|
|
259
|
+
users.push(user);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const comments = await commentModel.select(
|
|
264
|
+
{ mail: count.mail },
|
|
265
|
+
{ limit: 1 }
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
if (think.isEmpty(comments)) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const comment = comments[0];
|
|
272
|
+
|
|
273
|
+
if (think.isEmpty(comment)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const { nick, link } = comment;
|
|
277
|
+
const avatarUrl = await think.service('avatar').stringify(comment);
|
|
278
|
+
const avatar =
|
|
279
|
+
avatarProxy && !avatarUrl.includes(avatarProxy)
|
|
280
|
+
? avatarProxy + '?url=' + encodeURIComponent(avatarUrl)
|
|
281
|
+
: avatarUrl;
|
|
282
|
+
|
|
283
|
+
Object.assign(user, { nick, link, avatar });
|
|
284
|
+
users.push(user);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return users;
|
|
288
|
+
}
|
|
169
289
|
};
|
package/src/logic/user.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
const Base = require('./base');
|
|
2
2
|
|
|
3
3
|
module.exports = class extends Base {
|
|
4
|
+
/**
|
|
5
|
+
* @api {GET} /user user list
|
|
6
|
+
* @apiGroup User
|
|
7
|
+
* @apiVersion 0.0.1
|
|
8
|
+
*
|
|
9
|
+
* @apiParam {String} pageSize page size
|
|
10
|
+
*
|
|
11
|
+
* @apiSuccess (200) {Number} errno 0
|
|
12
|
+
* @apiSuccess (200) {String} errmsg return error message if error
|
|
13
|
+
*/
|
|
4
14
|
getAction() {
|
|
5
15
|
const { userInfo } = this.ctx.state;
|
|
6
16
|
|
|
7
17
|
if (think.isEmpty(userInfo) || userInfo.type !== 'administrator') {
|
|
8
|
-
|
|
18
|
+
this.rules = {
|
|
19
|
+
pageSize: {
|
|
20
|
+
int: { max: 50 },
|
|
21
|
+
default: 20,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return;
|
|
9
26
|
}
|
|
10
27
|
|
|
11
28
|
this.rules = {
|
|
@@ -17,6 +34,9 @@ module.exports = class extends Base {
|
|
|
17
34
|
int: { max: 100 },
|
|
18
35
|
default: 10,
|
|
19
36
|
},
|
|
37
|
+
email: {
|
|
38
|
+
string: true,
|
|
39
|
+
},
|
|
20
40
|
};
|
|
21
41
|
}
|
|
22
42
|
|
|
@@ -32,6 +52,12 @@ module.exports = class extends Base {
|
|
|
32
52
|
*
|
|
33
53
|
* @apiSuccess (200) {Number} errno 0
|
|
34
54
|
* @apiSuccess (200) {String} errmsg return error message if error
|
|
55
|
+
* @apiSuccess (200) {Object[]} data user list
|
|
56
|
+
* @apiSuccess (200) {String} data.nick comment user nick name
|
|
57
|
+
* @apiSuccess (200) {String} data.link comment user link
|
|
58
|
+
* @apiSuccess (200) {String} data.avatar comment user avatar
|
|
59
|
+
* @apiSuccess (200) {String} data.level comment user level
|
|
60
|
+
* @apiSuccess (200) {String} data.label comment user label
|
|
35
61
|
*/
|
|
36
62
|
postAction() {
|
|
37
63
|
return this.useCaptchaCheck();
|
|
@@ -260,6 +260,41 @@ module.exports = class extends Base {
|
|
|
260
260
|
options.group.join('_'),
|
|
261
261
|
where
|
|
262
262
|
);
|
|
263
|
+
|
|
264
|
+
if (!where._complex) {
|
|
265
|
+
if (cacheData.length) {
|
|
266
|
+
return cacheData;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const counts = await this.select(where, { field: options.group });
|
|
270
|
+
const countsMap = {};
|
|
271
|
+
|
|
272
|
+
for (let i = 0; i < counts.length; i++) {
|
|
273
|
+
const key = options.group
|
|
274
|
+
.map((item) => counts[i][item] || undefined)
|
|
275
|
+
.join('_');
|
|
276
|
+
|
|
277
|
+
if (!countsMap[key]) {
|
|
278
|
+
countsMap[key] = {};
|
|
279
|
+
|
|
280
|
+
for (let j = 0; j < options.group.length; j++) {
|
|
281
|
+
const field = options.group[j];
|
|
282
|
+
|
|
283
|
+
countsMap[key][field] = counts[i][field];
|
|
284
|
+
}
|
|
285
|
+
countsMap[key].count = 0;
|
|
286
|
+
}
|
|
287
|
+
countsMap[key].count += 1;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const ret = Object.values(countsMap);
|
|
291
|
+
|
|
292
|
+
// cache data
|
|
293
|
+
await this._setCmtGroupByMailUserIdCache(options.group.join('_'), ret);
|
|
294
|
+
|
|
295
|
+
return ret;
|
|
296
|
+
}
|
|
297
|
+
|
|
263
298
|
const cacheDataMap = {};
|
|
264
299
|
|
|
265
300
|
for (let i = 0; i < cacheData.length; i++) {
|