Skip to content

Commit

Permalink
Merge pull request #20 from TaleLin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pedro committed Jun 17, 2019
2 parents 62ef9ff + 2c33a84 commit 295ea95
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
11 changes: 11 additions & 0 deletions app/config/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
log: {
level: 'DEBUG',
dir: 'logs',
sizeLimit: 1024 * 1024 * 5,
requestLog: true,
file: true
}
};
4 changes: 3 additions & 1 deletion app/config/secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ module.exports = {
db: {
database: 'lin-cms5',
host: 'localhost',
dialect: 'mysql',
port: 3306,
username: 'root',
password: '123456',
logging: false
logging: false,
timezone: '+08:00'
},
secret:
'\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'
Expand Down
18 changes: 9 additions & 9 deletions app/dao/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class AdminDao {
type: db.QueryTypes.SELECT
}
);
let total = await db.query(
'SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin AND lin_user.delete_time IS NULL',
{
replacements: {
admin: UserAdmin.COMMON
},
type: db.QueryTypes.SELECT
}
);
let sql1 =
'SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin AND lin_user.delete_time IS NULL';
groupId && (sql1 += ` AND lin_user.group_id=${groupId}`);
let total = await db.query(sql1, {
replacements: {
admin: UserAdmin.COMMON
},
type: db.QueryTypes.SELECT
});
users.map(user => {
unsets(user, ['update_time', 'delete_time', 'password']);
user.create_time = dayjs(user.create_time).unix();
Expand Down
21 changes: 9 additions & 12 deletions app/extensions/file/local-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ const { File } = require('lin-mizar');
const { config } = require('lin-mizar/lin/config');
const fs = require('fs');
const path = require('path');
const { cloneDeep } = require('lodash');

class LocalUploader extends Uploader {
/**
* 处理文件流
* @param {object[]} files 文件流数组
* 处理文件对象
* { size, encoding, fieldname, filename, mimeType, data }
*/
async upload (files) {
const arr = [];
for (const stream of files) {
for (const file of files) {
// 由于stream的特性,当读取其中的数据时,它的buffer会被消费
// 所以此处深拷贝一份计算md5值
const tmpStream = cloneDeep(stream);
const md5 = this.generateMd5(tmpStream);
const md5 = this.generateMd5(file);
const siteDomain = config.getItem('siteDomain', 'http://localhost');
// 检查md5存在
const exist = await File.findOne({
Expand All @@ -26,31 +24,30 @@ class LocalUploader extends Uploader {
});
if (exist) {
arr.push({
key: stream.fieldname,
key: file.fieldname,
id: exist.id,
url: `${siteDomain}/assets/${exist.path}`
});
} else {
const { absolutePath, relativePath, realName } = this.getStorePath(
stream.filename
file.filename
);
const target = fs.createWriteStream(absolutePath);
await stream.pipe(target);
await target.write(file.data);
const ext = path.extname(realName);
// stream.filename tream.filedname stream.mimeType stream.readableLength
const saved = await File.createRecord(
{
path: relativePath,
// type: 1,
name: realName,
extension: ext,
size: stream._readableState.length,
size: file.size,
md5: md5
},
true
);
arr.push({
key: stream.fieldname,
key: file.fieldname,
id: saved.id,
url: `${siteDomain}/assets/${saved.path}`
});
Expand Down
2 changes: 1 addition & 1 deletion app/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const run = async () => {
const app = await createApp();
const port = config.getItem('port');
app.listen(port, () => {
app.context.logger.start(`listening at http://localhost:${port}`);
app.context.logger.info(`listening at http://localhost:${port}`);
});
};
// 启动应用
Expand Down
2 changes: 1 addition & 1 deletion app/validators/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LogFindValidator extends PaginateValidator {
if (!data.query) {
return true;
}
const end = data.query.start;
const end = data.query.end;
if (isOptional(end)) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion app/validators/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class ChangePasswordValidator extends LinValidator {
super();
this.new_password = new Rule(
'matches',
'密码长度必须在6~22位之间,包含字符、数字和 _ '
'密码长度必须在6~22位之间,包含字符、数字和 _ ',
/^[A-Za-z0-9_*&$#@]{6,22}$/
);
this.confirm_password = new Rule('isNotEmpty', '确认密码不可为空');
this.old_password = new Rule('isNotEmpty', '请输入旧密码');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lin-cms-koa",
"version": "0.1.0-beta.1",
"version": "0.1.0-beta.3",
"description": "simple and practical CMS implememted by koa",
"main": "app/starter.js",
"scripts": {
Expand Down Expand Up @@ -42,6 +42,6 @@
"koa-bodyparser": "^4.2.1",
"koa-mount": "^4.0.0",
"koa-static": "^5.0.0",
"lin-mizar": "0.1.0-beta.2"
"lin-mizar": "^0.1.0-beta.3"
}
}

0 comments on commit 295ea95

Please sign in to comment.