zeanium-node
Advanced tools
Comparing version 0.2.8 to 0.2.9
{ | ||
"name": "zeanium-node", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Zeanium for Node.js, simple http server and custome your business.", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"cheerio": "^0.20.0", | ||
"chinese-to-pinyin": "^0.1.4", | ||
"chokidar": "^1.4.3", | ||
@@ -29,0 +30,0 @@ "crypto": "0.0.3", |
@@ -30,3 +30,3 @@ zn.define('../action/Base', function (BaseAction) { | ||
ignore: true, | ||
format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
//format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
default: 'now()', | ||
@@ -41,4 +41,11 @@ header: { | ||
type: ['int', 11], | ||
convert: 'zn_convert_user({})', | ||
//ignore: true, | ||
default: '0' | ||
default: function (){ | ||
if(zn._request.session.hasItem()){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
}else { | ||
return 0; | ||
} | ||
} | ||
}, | ||
@@ -50,3 +57,3 @@ modifyTime: { | ||
auto_update: 'now()', | ||
format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
//format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
default: null | ||
@@ -57,4 +64,11 @@ }, | ||
type: ['int', 11], | ||
convert: 'zn_convert_user({})', | ||
ignore: true, | ||
default: '0' | ||
default: function (){ | ||
if(zn._request.session.hasItem()){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
}else { | ||
return 0; | ||
} | ||
} | ||
}, | ||
@@ -70,12 +84,3 @@ delFlag: { | ||
type: ['varchar', 250], | ||
default: '', | ||
common: { | ||
title: '备注' | ||
}, | ||
header: { | ||
}, | ||
input: { | ||
type: 'textarea' | ||
} | ||
default: '' | ||
} | ||
@@ -82,0 +87,0 @@ } |
@@ -9,2 +9,3 @@ zn.define('../action/Rights',function (RightsAction) { | ||
type: ['int', 11], | ||
convert: 'zn_convert_user({})', | ||
default: '0' | ||
@@ -21,3 +22,3 @@ }, | ||
type: ['varchar', 250], | ||
ignore: true, | ||
convert: 'zn_convert_users({})', | ||
default: ',' | ||
@@ -28,3 +29,2 @@ }, | ||
type: ['varchar', 250], | ||
ignore: true, | ||
default: ',' | ||
@@ -35,3 +35,2 @@ }, | ||
type: ['varchar', 250], | ||
ignore: true, | ||
default: ',' | ||
@@ -38,0 +37,0 @@ } |
@@ -37,3 +37,3 @@ /** | ||
return this._store.command | ||
.select(fields || this._ModelClass.getFields(false)) | ||
.select(((!fields||fields=='*')?this._ModelClass.getFields(false):fields)) | ||
.from(this._table) | ||
@@ -60,3 +60,3 @@ .where(_where) | ||
_end = _index * _size, | ||
_fields = fields || this._ModelClass.getFields(false), | ||
_fields = ((!fields||fields=='*')?this._ModelClass.getFields(false):fields), | ||
_table = this._table; | ||
@@ -63,0 +63,0 @@ var _sql = zn.sql.select(_fields) |
@@ -129,3 +129,4 @@ /** | ||
var _kAry = [], | ||
_vAry = []; | ||
_vAry = [], | ||
_self = this; | ||
@@ -137,4 +138,10 @@ this.constructor.getFields(true, function (field, key){ | ||
} | ||
_value = _value || field.default; | ||
if(_value!=null&&!field.ignore){ | ||
if(_value === undefined || _value === null){ | ||
var _default = field.default; | ||
if(zn.is(_default, 'function')){ | ||
_default = _default.call(_self, field, key); | ||
} | ||
_value = _default; | ||
} | ||
if(_value !== null && !field.ignore){ | ||
_kAry.push(key); | ||
@@ -151,4 +158,7 @@ _vAry.push(_value); | ||
this.constructor.getFields(true, function (field, key){ | ||
var _value = _self.get(key)||_self.__formatAutoUpdate(field.auto_update); | ||
if(_value!=null&&_value!=field.default){ | ||
var _value = _self.get(key); | ||
if(_value===undefined||_value===null){ | ||
_value = _self.__formatAutoUpdate(field.auto_update); | ||
} | ||
if(_value!=null){ | ||
_updates[key] = _value; | ||
@@ -155,0 +165,0 @@ } |
@@ -43,10 +43,14 @@ /** | ||
connection.query(_query, function(err, rows, fields) { | ||
if (err){ | ||
zn.error(err.message); | ||
_defer.reject(err, _self); | ||
zn.async.catch(err, _self); | ||
}else { | ||
_defer.resolve(rows, fields, _self); | ||
try { | ||
if (err){ | ||
zn.error(err.message); | ||
_defer.reject(err, _self); | ||
zn.async.catch(err, _self); | ||
}else { | ||
_defer.resolve(rows, fields, _self); | ||
} | ||
connection.release(); | ||
} catch (e) { | ||
_defer.reject(e, _self); | ||
} | ||
connection.release(); | ||
}); | ||
@@ -53,0 +57,0 @@ }else { |
@@ -135,3 +135,10 @@ /** | ||
case 'string': | ||
_ands.push(_self.__format([key, value])); | ||
var _argv = []; | ||
if(key.indexOf('&')!=-1){ | ||
_argv = key.split('&'); | ||
_argv.push(value); | ||
} else { | ||
_argv = [key, value]; | ||
} | ||
_ands.push(_self.__format(_argv)); | ||
break; | ||
@@ -149,3 +156,5 @@ } | ||
} | ||
var _key = _args.shift(), _operate = _args.shift(), _val = _args[0]; | ||
var _key = _args.shift(), | ||
_operate = _args.shift(), | ||
_val = _args[0]; | ||
if(zn.type(_val)=='function'){ | ||
@@ -152,0 +161,0 @@ _val = '('+_val.apply(this._context)+')'; |
@@ -98,3 +98,3 @@ /** | ||
_key, | ||
_validate = false, | ||
_validate, | ||
_controller, | ||
@@ -107,3 +107,3 @@ _routers = {}, | ||
_key = controller.getMeta('controller') || name; | ||
_validate = (controller.getMeta('validate') !== undefined) ? controller.getMeta('validate') : _validate; | ||
_validate = (controller.getMeta('validate') !== undefined) ? controller.getMeta('validate') : false; | ||
_controller = new controller(_self, _stores); | ||
@@ -113,3 +113,2 @@ controller._methods_.forEach(function (method, index){ | ||
if(_member.meta.router!==null){ | ||
_validate = (_member.meta.validate !== undefined) ? _member.meta.validate : _validate; | ||
_router = _member.meta.router || _member.name; | ||
@@ -122,3 +121,3 @@ _router = node_path.normalize(zn.SLASH + (_config.deploy||'') + zn.SLASH + _key + zn.SLASH + _router); | ||
appContext: _self, | ||
validate: _validate | ||
validate: (_member.meta.validate !== undefined) ? _member.meta.validate : _validate | ||
}; | ||
@@ -125,0 +124,0 @@ } |
@@ -51,7 +51,7 @@ zn.define([ | ||
var time = { | ||
s: '1000', | ||
n: '60000', | ||
h: '3600000', | ||
d: '86400000', | ||
w: '86400000 * 7' | ||
s: 1000, | ||
n: 60000, | ||
h: 3600000, | ||
d: 86400000, | ||
w: 86400000 * 7 | ||
} | ||
@@ -73,7 +73,7 @@ | ||
// httpOnly defaults to true. | ||
maxAge: 60 * 1000, | ||
maxAge: 1 * (time.h), | ||
//domain: '/', | ||
path: '/', | ||
expires: '', | ||
httpOnly: true, | ||
httpOnly: false, | ||
secure: false | ||
@@ -80,0 +80,0 @@ } |
@@ -7,3 +7,3 @@ zn.define(function () { | ||
method: 'GET/POST', | ||
value: function (request, response, $data, $post, $get, $files){ | ||
value: function (request, response, chain){ | ||
this.store().setup().then(function (data){ | ||
@@ -16,5 +16,28 @@ response.success(data); | ||
}, | ||
initModel: { | ||
method: 'GET/POST', | ||
argv: { | ||
model: null | ||
}, | ||
value: function (request, response, chain){ | ||
var _modelName = request.getValue('model'); | ||
var model = null, | ||
models = this._context._models; | ||
for(var key in models){ | ||
model = models[_modelName]; | ||
if(model){ | ||
var _table = model.getMeta('table'); | ||
if (_table&&!models[_table]){ | ||
this.store().createModel(model); | ||
break; | ||
} | ||
} | ||
} | ||
response.success("init model [" + _modelName + "] successful!!!"); | ||
} | ||
}, | ||
setup: { | ||
method: 'GET/POST', | ||
value: function (request, response, $data, $post, $get, $files){ | ||
value: function (request, response, chain){ | ||
@@ -31,3 +54,3 @@ var model = null, | ||
response.success("setup success!!!"); | ||
response.success("setup successful!!!"); | ||
} | ||
@@ -37,3 +60,3 @@ }, | ||
method: 'GET/POST', | ||
value: function (request, response, $data, $post, $get, $files){ | ||
value: function (request, response, chain){ | ||
var _routers = this._context._routers, | ||
@@ -54,3 +77,3 @@ _router = null, | ||
method: 'GET/POST', | ||
value: function (request, response, $data, $post, $get, $files){ | ||
value: function (request, response, chain){ | ||
response.success(Object.keys(this._context._appContexts)); | ||
@@ -57,0 +80,0 @@ } |
@@ -33,3 +33,2 @@ /** | ||
} | ||
return response.writePath(_app._config.root + zn.SLASH + _paths.join(zn.SLASH)), false; | ||
@@ -36,0 +35,0 @@ }, |
zn.define({ | ||
deploy: 'huchun', | ||
models: '/src/model/', | ||
@@ -4,0 +3,0 @@ controllers: '/src/controller/', |
@@ -94,3 +94,2 @@ zn.define(function () { | ||
var _action = this.__getModelAction(request, request.getValue('name')); | ||
console.log(_action); | ||
@@ -100,3 +99,3 @@ response.success('xxx'); | ||
}, | ||
select: { | ||
selectAllChildByPid: { | ||
method: 'GET/POST', | ||
@@ -107,2 +106,3 @@ argv: { | ||
where: '', | ||
pid: null, | ||
order: '' | ||
@@ -112,4 +112,56 @@ }, | ||
var _action = this.__getModelAction(request, request.getValue('model')); | ||
var _pid = request.getValue('pid'); | ||
var _where = request.getValue('where'); | ||
var _whereSql = "locate('," + _pid + ",',parentPath)<>0"; | ||
if(_where){ | ||
_whereSql += ' and ' + _where; | ||
} | ||
if(_action){ | ||
_action.select(request.getValue('fields'), _whereSql, request.getJSON('order')).then(function(data){ | ||
response.success(data); | ||
}); | ||
}else { | ||
response.error('Model is not exist!'); | ||
} | ||
} | ||
}, | ||
selectOne: { | ||
method: 'GET/POST', | ||
argv: { | ||
model: null, | ||
fields: '*', | ||
where: '', | ||
order: '' | ||
}, | ||
value: function (request, response, chain){ | ||
var _action = this.__getModelAction(request, request.getValue('model')); | ||
if(_action){ | ||
_action.select(request.getValue('fields'), request.getJSON('where'), request.getJSON('order')).then(function(data){ | ||
response.success(data.length?data[0]:null); | ||
}); | ||
}else { | ||
response.error('Model is not exist!'); | ||
} | ||
} | ||
}, | ||
select: { | ||
method: 'GET/POST', | ||
argv: { | ||
model: null, | ||
fields: '*', | ||
where: '', | ||
ifEnabledRights: 0 | ||
}, | ||
value: function (request, response, chain){ | ||
var _action = this.__getModelAction(request, request.getValue('model')); | ||
if(_action){ | ||
var _where = request.getJSON('where'); | ||
if(+request.getValue('ifEnabledRights')){ | ||
if(request.session.hasItem()){ | ||
_where['0&<>'] = 'zn_user_exist(' + request.session.getItem('@AdminUser').id + ', users, roles)'; | ||
}else { | ||
return response.sessionTimeout('Login Session Timeout.'); | ||
} | ||
} | ||
_action.select(request.getValue('fields'), _where).then(function(data){ | ||
response.success(data); | ||
@@ -127,6 +179,7 @@ }); | ||
fields: '*', | ||
where: '', | ||
order: '', | ||
where: '{}', | ||
order: '{}', | ||
pageIndex: 1, | ||
pageSize: 10 | ||
pageSize: 10, | ||
ifEnabledRights: 0 | ||
}, | ||
@@ -136,4 +189,15 @@ value: function (request, response, chain){ | ||
if(_action){ | ||
console.log(request.session.user); | ||
_action.paging(request.getValue('fields'), request.getJSON('where'), request.getJSON('order'), request.getInt('pageIndex'), request.getInt('pageSize')).then(function(data){ | ||
var _fields = request.getValue('fields'); | ||
var _where = request.getJSON('where'); | ||
if(_fields=='*'){ | ||
_fields = null; | ||
} | ||
if(+request.getValue('ifEnabledRights')){ | ||
if(request.session.hasItem()){ | ||
_where['0&<>'] = 'zn_user_exist(' + request.session.getItem('@AdminUser').id + ', users, roles)'; | ||
}else { | ||
return response.sessionTimeout('Login Session Timeout.'); | ||
} | ||
} | ||
_action.paging(_fields, _where, request.getJSON('order'), request.getInt('pageIndex'), request.getInt('pageSize')).then(function(data){ | ||
response.success(data); | ||
@@ -168,3 +232,4 @@ }); | ||
model: null, | ||
data: null | ||
data: null, | ||
where: null | ||
}, | ||
@@ -174,3 +239,3 @@ value: function (request, response, chain){ | ||
if(_action){ | ||
_action.updateNode(request.getJSON('data')).then(function (data){ | ||
_action.updateNode(request.getJSON('data'), request.getJSON('where')).then(function (data){ | ||
response.success(data); | ||
@@ -209,3 +274,7 @@ }); | ||
if(_action){ | ||
_action.deleteNode('id in ('+request.getValue('ids')+')').then(function (){ | ||
var _ids = request.getValue('ids'); | ||
if(_ids[0]==','){ | ||
_ids = '0' + _ids + '0'; | ||
} | ||
_action.deleteNode('id in (' + _ids + ')').then(function (){ | ||
response.success('删除成功'); | ||
@@ -212,0 +281,0 @@ }); |
zn.define([ | ||
'./RightsGroup', | ||
'./RightsMenu', | ||
'./RightsUser' | ||
], function (RightsGroup, RightsMenu, RightsUser) { | ||
'./RightsUser', | ||
'./RightsVar' | ||
], function (RightsMenu, RightsUser, RightsVar) { | ||
return { | ||
RightsGroup: RightsGroup, | ||
RightsMenu: RightsMenu, | ||
RightsUser: RightsUser | ||
RightsUser: RightsUser, | ||
RightsVar: RightsVar | ||
} | ||
}); |
@@ -11,7 +11,6 @@ zn.define(function () { | ||
}, | ||
logout: { | ||
getPCMenus: { | ||
method: 'GET/POST', | ||
argv: { | ||
username: null, | ||
password: null | ||
userId: null | ||
}, | ||
@@ -21,74 +20,2 @@ value: function (request, response, chain){ | ||
} | ||
}, | ||
login: { | ||
method: 'GET/POST', | ||
argv: { | ||
username: null, | ||
password: null | ||
}, | ||
value: function (request, response, chain){ | ||
this._action.findOne({ | ||
name: request.getValue('username'), | ||
pwd: request.getValue('password') | ||
}).then(function (user){ | ||
if(user){ | ||
request.session.user = user; | ||
response.success(user); | ||
} else { | ||
response.error('用户名或密码不对'); | ||
} | ||
}, function (error){ | ||
response.error(error.message); | ||
}); | ||
} | ||
}, | ||
addUser: { | ||
method: 'POST', | ||
argv: { | ||
}, | ||
value: function (request, response, chain){ | ||
this._action.insert({ name: 'name_0', pwd: 'pwd_0' }).then(function (rows, fields, command){ | ||
response.error('add success'); | ||
}); | ||
} | ||
}, | ||
updateUser: { | ||
method: 'GET/POST', | ||
argv: { | ||
userId: null | ||
}, | ||
value: function (request, response, chain){ | ||
this._action.update({ name: 'name_'+$data.userId, pwd: 'pwd_'+$data.userId }, { id: $data.userId }).then(function (a, b, c){ | ||
response.success('update success'); | ||
}); | ||
} | ||
}, | ||
findUserById: { | ||
method: 'GET/POST', | ||
argv: { | ||
userId: null | ||
}, | ||
value: function (request, response, chain){ | ||
this._action.findOne({ id: $data.userId }).then(function (data){ | ||
if(!data){ | ||
response.error('query no data'); | ||
}else { | ||
response.success(data); | ||
} | ||
}); | ||
} | ||
}, | ||
getAllUsers: { | ||
method: 'GET/POST', | ||
value: function (request, response, chain) { | ||
this._action.select().then(function (data){ | ||
if(!data){ | ||
response.error('query no data'); | ||
}else { | ||
response.success(data); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -95,0 +22,0 @@ } |
@@ -1,2 +0,2 @@ | ||
zn.define(function () { | ||
zn.define(['node:chinese-to-pinyin'],function (pinyin) { | ||
@@ -20,4 +20,4 @@ return zn.Controller('user',{ | ||
argv: { | ||
username: null, | ||
password: null | ||
name: null, | ||
pwd: null | ||
}, | ||
@@ -27,3 +27,11 @@ value: function (request, response, chain){ | ||
if(user){ | ||
request.session.user = user; | ||
/* | ||
console.log(new Date().toDateString()); | ||
this._action.update({ lastLoginTime: new Date().toDateString()}, { id: user.id }).then(function (data){ | ||
console.log(data); | ||
}, function (){ | ||
console.log(data); | ||
});*/ | ||
//user['@session'] = request.session.serialize(); | ||
request.session.setItem('@AdminUser', user); | ||
response.success(user); | ||
@@ -38,12 +46,6 @@ } else { | ||
}, | ||
addUser: { | ||
method: 'POST', | ||
argv: { | ||
}, | ||
getSession: { | ||
method: 'GET', | ||
value: function (request, response, chain){ | ||
this._action.insert(request.getValue()).then(function (rows, fields, command){ | ||
response.error('add success'); | ||
}); | ||
response.success(request.session.getItem('@AdminUser')); | ||
} | ||
@@ -58,3 +60,3 @@ }, | ||
value: function (request, response, chain){ | ||
this._action.update({ name: 'name_'+$data.userId, pwd: 'pwd_'+$data.userId }, { id: $data.userId }).then(function (a, b, c){ | ||
this._action.update(request.getValue('data'), { id: request.getValue('userId') }).then(function (a, b, c){ | ||
response.success('update success'); | ||
@@ -70,3 +72,3 @@ }); | ||
value: function (request, response, chain){ | ||
this._action.findOne({ id: $data.userId }).then(function (data){ | ||
this._action.selectOne({ id: request.getValue('userId') }).then(function (data){ | ||
if(!data){ | ||
@@ -73,0 +75,0 @@ response.error('query no data'); |
zn.define([ | ||
'./RightsUser', | ||
'./RightsRole', | ||
'./RightsGroup', | ||
'./RightsResource', | ||
'./RightsButton', | ||
'./RightsMenu', | ||
'./RightsVar' | ||
],function (RightsUser, RightsRole, RightsGroup, RightsResource, RightsButton, RightsMenu, RightsVar){ | ||
],function (RightsUser, RightsRole, RightsButton, RightsMenu, RightsVar){ | ||
@@ -14,4 +12,2 @@ return { | ||
RightsRole: RightsRole, | ||
RightsGroup: RightsGroup, | ||
RightsResource: RightsResource, | ||
RightsButton: RightsButton, | ||
@@ -18,0 +14,0 @@ RightsMenu: RightsMenu, |
@@ -17,11 +17,6 @@ zn.define(function () { | ||
}, | ||
groupId: { | ||
roleType: { | ||
value: null, | ||
type: ['int', 11], | ||
default: '0' | ||
}, | ||
userIds: { | ||
value: null, | ||
type: ['varchar', 500], | ||
default: ',' | ||
} | ||
@@ -28,0 +23,0 @@ } |
@@ -1,2 +0,2 @@ | ||
zn.define(function () { | ||
zn.define(['node:chinese-to-pinyin'], function (pinyin) { | ||
@@ -15,2 +15,32 @@ var model = zn.db.common.model; | ||
}, | ||
pinYin: { | ||
value: null, | ||
type: ['varchar', 20], | ||
default: function (){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true }); | ||
} | ||
}, | ||
pinYinFirstChar: { | ||
value: null, | ||
type: ['varchar', 20], | ||
default: function (){ | ||
var _firsts = []; | ||
zn.each(pinyin(this.get('name'), { noTone: true, filterChinese: true }).split(' '), function (value, index){ | ||
_firsts.push(value[0].toUpperCase()); | ||
}); | ||
return _firsts.join(''); | ||
} | ||
}, | ||
firstChar: { | ||
value: null, | ||
type: ['varchar', 2], | ||
default: function (){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true })[0].toUpperCase(); | ||
} | ||
}, | ||
roleIds: { | ||
value: null, | ||
type: ['varchar', 500], | ||
default: ',' | ||
}, | ||
name: { | ||
@@ -24,3 +54,3 @@ value: null, | ||
type: ['varchar', 100], | ||
default: '' | ||
default: '1234' | ||
}, | ||
@@ -27,0 +57,0 @@ email: { |
@@ -13,2 +13,7 @@ zn.define(function () { | ||
properties: { | ||
menuId: { | ||
value: null, | ||
type: ['int', 11], | ||
default: '0' | ||
}, | ||
url: { | ||
@@ -15,0 +20,0 @@ value: null, |
@@ -19,2 +19,3 @@ /** | ||
$files: null, | ||
$uploadConfig: null, | ||
context: null, | ||
@@ -31,4 +32,4 @@ applicationContext: null, | ||
if(!value){ return false; } | ||
this.reset(); | ||
this._serverRequest = value; | ||
this._errors = []; | ||
this.__doSession(); | ||
@@ -42,2 +43,7 @@ this.__parseUrlData(); | ||
init: function (context, serverRequest){ | ||
this.reset(); | ||
this._context = context; | ||
this.serverRequest = serverRequest; | ||
}, | ||
reset: function (){ | ||
this._$data = {}; | ||
@@ -48,4 +54,2 @@ this._$post = {}; | ||
this._errors = []; | ||
this._context = context; | ||
this.serverRequest = serverRequest; | ||
}, | ||
@@ -149,10 +153,10 @@ getJSON: function (inName){ | ||
_upload = _config.upload || {}, | ||
_root = (_config.root || __dirname)+'/uploads/'; | ||
_root = (_config.root || __dirname) + zn.SLASH + 'uploads' + zn.SLASH; | ||
return zn.extend(_upload, { | ||
root: _root, | ||
temp: 'temp/', | ||
catalog: 'catalog/', | ||
temp: 'temp' + zn.SLASH, | ||
catalog: 'catalog' + zn.SLASH, | ||
forward: '', | ||
server: 'http://localhost:8888/tj/' | ||
fileServer: null | ||
}); | ||
@@ -162,13 +166,23 @@ }, | ||
var _request = this._serverRequest, | ||
_upload = this.__getUploadInfo(), | ||
_incomingForm = new formidable.IncomingForm(); | ||
_data = _request.data; | ||
this._upload = _upload; | ||
_incomingForm.uploadDir = _upload.root + _upload.temp; //文件上传 临时文件存放路径 | ||
if(_request.data){ | ||
var _data = _request.data; | ||
if(_data){ | ||
this._$post = _data.fields; | ||
this._$files = _data.files; | ||
callback(zn.extend({ upload: _upload }, _data)); | ||
this._$uploadConfig = _data.uploadConfig; | ||
callback(_data); | ||
} else { | ||
var _upload = this.__getUploadInfo(), | ||
_incomingForm = new formidable.IncomingForm(), | ||
_uploadDir = _upload.root + _upload.temp; //文件上传 临时文件存放路径; | ||
if(!fs.existsSync(_upload.root)){ | ||
fs.mkdirSync(_upload.root); | ||
} | ||
if(!fs.existsSync(_uploadDir)){ | ||
fs.mkdirSync(_uploadDir); | ||
} | ||
_incomingForm.uploadDir = _uploadDir; | ||
_incomingForm.parse(_request,function(error, fields, files){ | ||
@@ -178,9 +192,11 @@ if(error){ | ||
} else { | ||
_request.data = { | ||
_data = _request.data = { | ||
fields: fields, | ||
files: files | ||
files: files, | ||
uploadConfig: _upload | ||
}; | ||
this._$post = fields; | ||
this._$files = files; | ||
callback({ upload: _upload, fields: fields, files: files }); | ||
this._$uploadConfig = _upload; | ||
callback(_data); | ||
} | ||
@@ -194,20 +210,33 @@ }.bind(this)); | ||
_file = _name + '.' + _ext, | ||
_upload = upload || this._upload, | ||
_root = _upload.root; | ||
_upload = upload || this._$uploadConfig, | ||
_root = _upload.root, | ||
_fileServer = _upload.fileServer, | ||
_sourceFile = _root + _upload.temp + _name, | ||
_targetDir = _root + _upload.catalog; | ||
var _path = _root + _upload.temp + _name, | ||
_newPath = _root + _upload.catalog + _file; | ||
if(!fs.existsSync(_targetDir)){ | ||
fs.mkdirSync(_targetDir); | ||
} | ||
var _targetFile = _targetDir + _file; | ||
_targetFile = _targetFile.replace(/\\/g, '/'); | ||
_sourceFile = _sourceFile.replace(/\\/g, '/'); | ||
_path = _path.replace(/\\/g, '/'); | ||
_newPath = _newPath.replace(/\\/g, '/'); | ||
fs.renameSync(_path, _newPath); | ||
fs.renameSync(_sourceFile, _targetFile); | ||
var _paths = this.paths.slice(0); | ||
_paths.pop(); | ||
_paths.pop(); | ||
var _wwwAry = [this._context._root].concat(_paths).concat(['uploads', _upload.catalog, _file]); | ||
if(!_fileServer){ | ||
_fileServer = _wwwAry.join(zn.SLASH); | ||
}else { | ||
_fileServer = _fileServer + zn.SLASH + _upload.catalog + zn.SLASH + _file; | ||
} | ||
return { | ||
path: _newPath, | ||
name: file.name, | ||
size: file.size, | ||
fileType: file.type, | ||
file: _file, | ||
name: file.name, | ||
ext: _ext, | ||
url: path.normalize(_upload.server + '/' + _upload.catalog + '/' + _file), | ||
path: _targetFile, | ||
url: _fileServer, | ||
lastModifiedDate: file.lastModifiedDate.toISOString().slice(0, 19) | ||
@@ -227,2 +256,12 @@ }; | ||
}, | ||
clearTempFiles: function (){ | ||
var _data = this._serverRequest.data; | ||
if(_data && _data.files){ | ||
zn.each(_data.files, function (file){ | ||
if(fs.existsSync(file.path)){ | ||
fs.unlinkSync(file.path); | ||
} | ||
}); | ||
} | ||
}, | ||
__uploadFiles: function (files){ | ||
@@ -229,0 +268,0 @@ var _paths = []; |
@@ -54,5 +54,7 @@ /** | ||
} | ||
if(_handler.validate && !request.session.hasItem()){ | ||
return response.error('Session is invalid. Please login into system first.'); | ||
if(!!_handler.validate && !_request.session.hasItem()){ | ||
return response.sessionTimeout('Session is invalid. Please login into system first.'); | ||
} | ||
zn._request = _request; | ||
zn._response = _response; | ||
_controller[_action].call(_controller, request, response, this); | ||
@@ -62,2 +64,3 @@ } catch (e) { | ||
console.log(e.stack); | ||
response.error(e.message); | ||
} | ||
@@ -64,0 +67,0 @@ }, |
@@ -68,6 +68,7 @@ /** | ||
var _crossSetting = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With', | ||
'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS', | ||
'Access-Control-Max-Age': '3600', | ||
'Access-Control-Allow-Origin': this._request._serverRequest.headers.origin, | ||
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE, PUT', | ||
'Access-Control-Allow-Headers': 'Accept,Accept-Charset,Accept-Encoding,Accept-Language,Connection,Content-Type,Cookie,DNT,Host,Keep-Alive,Origin,Referer,User-Agent,X-CSRF-Token,X-Requested-With', | ||
"Access-Control-Allow-Credentials": true, | ||
'Access-Control-Max-Age': '3600',//一个小时时间 | ||
'X-Powered-By': 'zeanium-node@1.2.0', | ||
@@ -90,2 +91,3 @@ 'Content-Type': 'application/json;charset=utf-8' | ||
this._request.clearTempFiles(); | ||
this._serverResponse.writeHead(httpStatus, _args); | ||
@@ -110,2 +112,4 @@ }, | ||
this._serverResponse.write(_data, inEncode); | ||
zn._request = null; | ||
zn._response = null; | ||
}, | ||
@@ -239,2 +243,3 @@ writeContent: function (status, content, contentType){ | ||
error: function (inData, inEncode){ | ||
this.writeHead(500,{}); | ||
this.__writeJson({ | ||
@@ -245,2 +250,9 @@ result: inData, | ||
}, | ||
sessionTimeout: function (inData, inEncode){ | ||
this.writeHead(401,{}); | ||
this.__writeJson({ | ||
result: inData, | ||
status: 401 | ||
}, inEncode); | ||
}, | ||
forword: function (url, isInternal){ | ||
@@ -247,0 +259,0 @@ this.fire('end', this); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
391500
251
9622
9
+ Addedchinese-to-pinyin@^0.1.4
+ Addedchinese-to-pinyin@0.1.11(transitive)