Skip to content

Commit 295ea95

Browse files
author
pedro
authored
Merge pull request #20 from TaleLin/dev
Dev
2 parents 62ef9ff + 2c33a84 commit 295ea95

File tree

8 files changed

+38
-27
lines changed

8 files changed

+38
-27
lines changed

app/config/log.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = {
4+
log: {
5+
level: 'DEBUG',
6+
dir: 'logs',
7+
sizeLimit: 1024 * 1024 * 5,
8+
requestLog: true,
9+
file: true
10+
}
11+
};

app/config/secure.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module.exports = {
44
db: {
55
database: 'lin-cms5',
66
host: 'localhost',
7+
dialect: 'mysql',
78
port: 3306,
89
username: 'root',
910
password: '123456',
10-
logging: false
11+
logging: false,
12+
timezone: '+08:00'
1113
},
1214
secret:
1315
'\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'

app/dao/admin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class AdminDao {
3838
type: db.QueryTypes.SELECT
3939
}
4040
);
41-
let total = await db.query(
42-
'SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin AND lin_user.delete_time IS NULL',
43-
{
44-
replacements: {
45-
admin: UserAdmin.COMMON
46-
},
47-
type: db.QueryTypes.SELECT
48-
}
49-
);
41+
let sql1 =
42+
'SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin AND lin_user.delete_time IS NULL';
43+
groupId && (sql1 += ` AND lin_user.group_id=${groupId}`);
44+
let total = await db.query(sql1, {
45+
replacements: {
46+
admin: UserAdmin.COMMON
47+
},
48+
type: db.QueryTypes.SELECT
49+
});
5050
users.map(user => {
5151
unsets(user, ['update_time', 'delete_time', 'password']);
5252
user.create_time = dayjs(user.create_time).unix();

app/extensions/file/local-uploader.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ const { File } = require('lin-mizar');
33
const { config } = require('lin-mizar/lin/config');
44
const fs = require('fs');
55
const path = require('path');
6-
const { cloneDeep } = require('lodash');
76

87
class LocalUploader extends Uploader {
98
/**
10-
* 处理文件流
11-
* @param {object[]} files 文件流数组
9+
* 处理文件对象
10+
* { size, encoding, fieldname, filename, mimeType, data }
1211
*/
1312
async upload (files) {
1413
const arr = [];
15-
for (const stream of files) {
14+
for (const file of files) {
1615
// 由于stream的特性,当读取其中的数据时,它的buffer会被消费
1716
// 所以此处深拷贝一份计算md5值
18-
const tmpStream = cloneDeep(stream);
19-
const md5 = this.generateMd5(tmpStream);
17+
const md5 = this.generateMd5(file);
2018
const siteDomain = config.getItem('siteDomain', 'http://localhost');
2119
// 检查md5存在
2220
const exist = await File.findOne({
@@ -26,31 +24,30 @@ class LocalUploader extends Uploader {
2624
});
2725
if (exist) {
2826
arr.push({
29-
key: stream.fieldname,
27+
key: file.fieldname,
3028
id: exist.id,
3129
url: `${siteDomain}/assets/${exist.path}`
3230
});
3331
} else {
3432
const { absolutePath, relativePath, realName } = this.getStorePath(
35-
stream.filename
33+
file.filename
3634
);
3735
const target = fs.createWriteStream(absolutePath);
38-
await stream.pipe(target);
36+
await target.write(file.data);
3937
const ext = path.extname(realName);
40-
// stream.filename tream.filedname stream.mimeType stream.readableLength
4138
const saved = await File.createRecord(
4239
{
4340
path: relativePath,
4441
// type: 1,
4542
name: realName,
4643
extension: ext,
47-
size: stream._readableState.length,
44+
size: file.size,
4845
md5: md5
4946
},
5047
true
5148
);
5249
arr.push({
53-
key: stream.fieldname,
50+
key: file.fieldname,
5451
id: saved.id,
5552
url: `${siteDomain}/assets/${saved.path}`
5653
});

app/starter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const run = async () => {
2020
const app = await createApp();
2121
const port = config.getItem('port');
2222
app.listen(port, () => {
23-
app.context.logger.start(`listening at http://localhost:${port}`);
23+
app.context.logger.info(`listening at http://localhost:${port}`);
2424
});
2525
};
2626
// 启动应用

app/validators/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LogFindValidator extends PaginateValidator {
2828
if (!data.query) {
2929
return true;
3030
}
31-
const end = data.query.start;
31+
const end = data.query.end;
3232
if (isOptional(end)) {
3333
return true;
3434
}

app/validators/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class ChangePasswordValidator extends LinValidator {
6262
super();
6363
this.new_password = new Rule(
6464
'matches',
65-
'密码长度必须在6~22位之间,包含字符、数字和 _ '
65+
'密码长度必须在6~22位之间,包含字符、数字和 _ ',
66+
/^[A-Za-z0-9_*&$#@]{6,22}$/
6667
);
6768
this.confirm_password = new Rule('isNotEmpty', '确认密码不可为空');
6869
this.old_password = new Rule('isNotEmpty', '请输入旧密码');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-cms-koa",
3-
"version": "0.1.0-beta.1",
3+
"version": "0.1.0-beta.3",
44
"description": "simple and practical CMS implememted by koa",
55
"main": "app/starter.js",
66
"scripts": {
@@ -42,6 +42,6 @@
4242
"koa-bodyparser": "^4.2.1",
4343
"koa-mount": "^4.0.0",
4444
"koa-static": "^5.0.0",
45-
"lin-mizar": "0.1.0-beta.2"
45+
"lin-mizar": "^0.1.0-beta.3"
4646
}
4747
}

0 commit comments

Comments
 (0)