zeanium-node
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "zeanium-node", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Zeanium for Node.js, simple http server and custome your business.", | ||
@@ -34,2 +34,6 @@ "main": "index.js", | ||
"mysql": "^2.10.2", | ||
"nodemailer": "^2.6.4", | ||
"officegen": "^0.4.0", | ||
"request": "^2.72.0", | ||
"xlsx": "^0.8.0", | ||
"request": "^2.72.0" | ||
@@ -36,0 +40,0 @@ }, |
@@ -1,3 +0,3 @@ | ||
exports = module.exports = { | ||
module.exports = { | ||
}; |
@@ -5,2 +5,8 @@ zn.define(function () { | ||
properties: { | ||
fileIds: { | ||
value: null, | ||
type: ['varchar', 250], | ||
ignore: true, | ||
default: ',' | ||
}, | ||
files: { | ||
@@ -7,0 +13,0 @@ value: null, |
@@ -44,3 +44,7 @@ zn.define('../action/Base', function (BaseAction) { | ||
if(zn._request.session.hasItem()){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
if(zn._request.session.getItem('@AdminUser')){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
}else { | ||
return 0; | ||
} | ||
}else { | ||
@@ -47,0 +51,0 @@ return 0; |
@@ -6,4 +6,5 @@ zn.define([ | ||
'./Rights', | ||
'./Attachment' | ||
], function (Base, Tag, Tree, Rights, Attachment) { | ||
'./Attachment', | ||
'./File' | ||
], function (Base, Tag, Tree, Rights, Attachment, File) { | ||
@@ -15,5 +16,6 @@ return { | ||
Rights: Rights, | ||
Attachment: Attachment | ||
Attachment: Attachment, | ||
File: File | ||
} | ||
}); |
@@ -27,8 +27,16 @@ zn.define('../action/Rights',function (RightsAction) { | ||
type: ['varchar', 250], | ||
convert: 'zn_convert_roles({})', | ||
default: ',' | ||
}, | ||
observers: { | ||
observeUsers: { | ||
value: null, | ||
type: ['varchar', 250], | ||
convert: 'zn_convert_users({})', | ||
default: ',' | ||
}, | ||
observeRoles: { | ||
value: null, | ||
type: ['varchar', 250], | ||
convert: 'zn_convert_roles({})', | ||
default: ',' | ||
} | ||
@@ -35,0 +43,0 @@ } |
@@ -6,2 +6,7 @@ zn.define('../action/Tree',function (TreeAction) { | ||
properties: { | ||
type: { | ||
value: null, | ||
type: ['int', 11], | ||
default: '0' | ||
}, | ||
pid: { | ||
@@ -36,7 +41,2 @@ value: null, | ||
}, | ||
ext: { | ||
value: null, | ||
type: ['varchar', 200], | ||
default: '{}' | ||
}, | ||
parentPath: { | ||
@@ -47,2 +47,7 @@ value: null, | ||
default: ',' | ||
}, | ||
ext: { | ||
value: null, | ||
type: ['varchar', 500], | ||
default: '' | ||
} | ||
@@ -49,0 +54,0 @@ } |
@@ -7,2 +7,9 @@ /** | ||
var Action = zn.Class('zn.db.data.Action', { | ||
properties: { | ||
modelAlise: { | ||
set: function (value){ | ||
this._table = value; | ||
} | ||
} | ||
}, | ||
methods: { | ||
@@ -68,3 +75,3 @@ init: { | ||
.build() + ';'; | ||
_sql += zn.sql.select('count(id) as count').from(_table).where(where).build(); | ||
_sql += zn.sql.select('count(*) as count').from(_table).where(where).build(); | ||
return this._store.command.query(_sql); | ||
@@ -71,0 +78,0 @@ }, |
@@ -82,3 +82,3 @@ /** | ||
} | ||
var _default = this.__getDefaultValue(property); | ||
var _default = this.__getDefaultValue(property, key); | ||
@@ -96,10 +96,17 @@ if(_default){ | ||
}, | ||
__getDefaultValue: function (property) { | ||
__getDefaultValue: function (property, key) { | ||
if(property.default !== undefined){ | ||
var _type = property.type[0], | ||
_value = property.default; | ||
if(zn.is(_value, 'function')){ | ||
_value = _value.call(this, property, key); | ||
} | ||
switch(_type){ | ||
case 'nvarchar': | ||
case 'varchar': | ||
_value = "'"+_value+"'"; | ||
if(_value.indexOf('{') === 0 && _value.indexOf('}') === (_value.length-1)){ | ||
_value = _value.substring(1, _value.length-1); | ||
}else { | ||
_value = "'"+_value+"'"; | ||
} | ||
break; | ||
@@ -106,0 +113,0 @@ case 'date': |
@@ -37,3 +37,4 @@ /** | ||
_query = _argv.shift().format(_argv), | ||
_self = this; | ||
_self = this, | ||
_msg = ''; | ||
@@ -44,17 +45,22 @@ zn.debug(_query); | ||
connection.query(_query, function(err, rows, fields) { | ||
try { | ||
if (err){ | ||
zn.error(err.message); | ||
_defer.reject(err, _self); | ||
zn.async.catch(err, _self); | ||
}else { | ||
_defer.resolve(rows, fields, _self); | ||
if (err){ | ||
_msg = 'MySql Connection query error: ' + err.message; | ||
zn.error(_msg); | ||
_defer.reject(err, _self); | ||
zn.async.catch(err, _self); | ||
if(zn._response){ | ||
zn._response.error(_msg); | ||
} | ||
connection.release(); | ||
} catch (e) { | ||
_defer.reject(e, _self); | ||
}else { | ||
_defer.resolve(rows, fields, _self); | ||
} | ||
connection.release(); | ||
}); | ||
}else { | ||
zn.error(err.message); | ||
_msg = 'MySql Pool getConnection error: ' + JSON.stringify(err); | ||
zn.error(_msg); | ||
_defer.reject(err, _self); | ||
if(zn._response){ | ||
zn._response.error(_msg); | ||
} | ||
} | ||
@@ -61,0 +67,0 @@ }); |
@@ -128,3 +128,5 @@ /** | ||
__dataToWhere: function (data) { | ||
var _ands = [], _self = this; | ||
var _ands = [], | ||
_ors = [], | ||
_self = this; | ||
zn.each(data, function (value, key){ | ||
@@ -137,15 +139,27 @@ switch(zn.type(key)){ | ||
var _argv = []; | ||
if(key.indexOf('&')!=-1){ | ||
_argv = key.split('&'); | ||
if(key.indexOf('|')!=-1){ | ||
key = key.split('@').shift(); | ||
_argv = key.split('|'); | ||
_argv.push(value); | ||
_ors.push(_self.__format(_argv)); | ||
} else { | ||
_argv = [key, value]; | ||
if(key.indexOf('&')!=-1){ | ||
key = key.split('@').shift(); | ||
_argv = key.split('&'); | ||
_argv.push(value); | ||
} else { | ||
_argv = [key, value]; | ||
} | ||
_ands.push(_self.__format(_argv)); | ||
} | ||
_ands.push(_self.__format(_argv)); | ||
break; | ||
} | ||
}); | ||
if(_ands.length){ | ||
return '('+_ands.join(' and ')+')'; | ||
var _and = _ands.length?('('+_ands.join(' and ')+')'):'', | ||
_or = _ors.length?('('+_ors.join(' or ')+')'):''; | ||
if(_and&&_or){ | ||
return _and + ' and ' + _or; | ||
} | ||
return _and + _or; | ||
}, | ||
@@ -152,0 +166,0 @@ __format: function (args){ |
@@ -32,3 +32,3 @@ /** | ||
this._appRoot = this._root = serverContext._root + zn.SLASH + this._deploy; | ||
this.__initDBStore(appConfig.databases); | ||
this.__initDBStore(appConfig.databases||serverContext.config.databases); | ||
this.__registerApplicationController(); | ||
@@ -35,0 +35,0 @@ }, |
@@ -63,2 +63,3 @@ zn.define([ | ||
catalog: '/webapps/', | ||
timeout: 12000, | ||
mode: 'debug', //release, debug, view, | ||
@@ -65,0 +66,0 @@ indexs: ['index.html', 'index.htm', 'default.html', 'default.htm'], |
@@ -1,2 +0,2 @@ | ||
zn.define(function () { | ||
zn.define(['node:xlsx'], function (xlsx) { | ||
@@ -41,3 +41,2 @@ return zn.Controller('', { | ||
value: function (request, response, chain){ | ||
var model = null, | ||
@@ -77,2 +76,79 @@ models = this._context._models; | ||
} | ||
}, | ||
uploadFiles: { | ||
method: 'POST', | ||
value: function (request, response, chain){ | ||
var _files = request.$files, _result = []; | ||
zn.each(_files, function (file, key){ | ||
_result.push(request.uploadFile(file)); | ||
}); | ||
response.success(_result); | ||
} | ||
}, | ||
importXlsx: { | ||
method: 'POST', | ||
argv: { | ||
start: 1, | ||
model: null, | ||
fields: [], | ||
vars: '{}' | ||
}, | ||
value: function (request, response, chain){ | ||
var _files = request.$files, | ||
_result = [], | ||
_sqls = [], | ||
_store = this.store(), | ||
_start = request.getInt('start'), | ||
_model = request.getValue('model'), | ||
_fields = request.getValue('fields'), | ||
_vars = JSON.parse(request.getValue('vars')||'{}'), | ||
_len = _fields.split(',').length; | ||
zn.each(_files, function (file, key){ | ||
var _file = request.uploadFile(file); | ||
var _worksheet = xlsx.readFile(_file.path); | ||
Object.keys(_worksheet.Sheets).map((name)=>{ | ||
var _data = xlsx.utils.sheet_to_json(_worksheet.Sheets[name], { | ||
header: 1, | ||
raw: true | ||
}); | ||
if(_data.length){ | ||
zn.each(_data, function (item, index){ | ||
if(index > (_start-1)){ | ||
if(item.length){ | ||
var _values = [], | ||
_value = null; | ||
for(var i=0; i<_len; i++){ | ||
_value = item[i]||''; | ||
if(_vars[i]){ | ||
_value = _vars[i][_value]; | ||
} | ||
if(!zn.is(_value, 'number')){ | ||
_value = "\'" + _value + "\'"; | ||
} | ||
_values.push(_value); | ||
} | ||
_sqls.push("insert into {0} ({1}) values ({2})".format(_model, _fields, _values.join(','))); | ||
} | ||
} | ||
}); | ||
} | ||
_result.push({ | ||
title: name, | ||
data: _data | ||
}); | ||
}); | ||
}); | ||
_store.query(_sqls.join(';')).then(function (){ | ||
response.success(_result); | ||
}, function (err){ | ||
response.error('Import Error: ' + err.message); | ||
}); | ||
} | ||
} | ||
@@ -79,0 +155,0 @@ } |
@@ -125,9 +125,12 @@ /** | ||
if(path.substr(-3, 3)=='.js'){ | ||
zn.debug('[' + path + '] Changed.'); | ||
zn.info('Redeploying......'); | ||
zn.debug(event + ': ' + path); | ||
zn.module.unloadModule(path); | ||
this.__scanWebPath(true); | ||
this.__doFileChange(); | ||
} | ||
}.bind(this)); | ||
}, | ||
__doFileChange: function (){ | ||
zn.info('Redeploying......'); | ||
this.__scanWebPath(true); | ||
}, | ||
__onLoaded: function(path){ | ||
@@ -134,0 +137,0 @@ if(path){ |
@@ -19,3 +19,7 @@ zn.define(['node:chinese-to-pinyin'], function (pinyin) { | ||
default: function (){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true }); | ||
if(this.get('name')){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true }); | ||
}else { | ||
return ''; | ||
} | ||
} | ||
@@ -27,7 +31,11 @@ }, | ||
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(''); | ||
if(this.get('name')){ | ||
var _firsts = []; | ||
zn.each(pinyin(this.get('name'), { noTone: true, filterChinese: true }).split(' '), function (value, index){ | ||
_firsts.push(value[0].toUpperCase()); | ||
}); | ||
return _firsts.join(''); | ||
}else { | ||
return ''; | ||
} | ||
} | ||
@@ -39,3 +47,7 @@ }, | ||
default: function (){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true })[0].toUpperCase(); | ||
if(this.get('name')){ | ||
return pinyin(this.get('name'), { noTone: true, filterChinese: true })[0].toUpperCase(); | ||
}else { | ||
return ''; | ||
} | ||
} | ||
@@ -42,0 +54,0 @@ }, |
@@ -181,2 +181,3 @@ /** | ||
//_incomingForm.keepExtensions = true; //使用文件的原扩展名 | ||
_incomingForm.uploadDir = _uploadDir; | ||
@@ -202,7 +203,6 @@ _incomingForm.parse(_request,function(error, fields, files){ | ||
var _name = file.path.split(path.sep).pop(), | ||
_ext = file.type.split('/').pop(), | ||
_ext = file.name.split('.').pop(), | ||
_file = _name + '.' + _ext, | ||
_upload = upload || this._$uploadConfig, | ||
_root = _upload.root, | ||
_fileServer = _upload.fileServer, | ||
_sourceFile = _root + _upload.temp + _name, | ||
@@ -214,16 +214,12 @@ _targetDir = _root + _upload.catalog; | ||
} | ||
if(_upload.keepOriginName){ | ||
_file = file.name; | ||
} | ||
var _targetFile = _targetDir + _file; | ||
_targetFile = _targetFile.replace(/\\/g, '/'); | ||
_sourceFile = _sourceFile.replace(/\\/g, '/'); | ||
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; | ||
} | ||
var _url = [zn.SLASH, this._applicationContext._deploy].concat(['uploads', _upload.catalog, _file]).join(zn.SLASH); | ||
return { | ||
@@ -236,3 +232,3 @@ name: file.name, | ||
path: _targetFile, | ||
url: _fileServer, | ||
url: path.normalize(_url), | ||
lastModifiedDate: file.lastModifiedDate.toISOString().slice(0, 19) | ||
@@ -239,0 +235,0 @@ }; |
@@ -48,10 +48,27 @@ /** | ||
_action = _handler.action, | ||
_meta = _controller.member(_action).meta, | ||
_meta = _controller.member(_action).meta||{}, | ||
_values = this.__checkMeta(_meta, request, response); | ||
this._response.setTimeout(_meta.timeout); | ||
if(!_values){ | ||
return false; | ||
} | ||
if(!!_handler.validate && !_request.session.hasItem()){ | ||
return response.sessionTimeout('Session is invalid. Please login into system first.'); | ||
if(!!_handler.validate){ | ||
if(!_request.session.hasItem()){ | ||
return response.sessionTimeout('Session is invalid. Please login into system first.'); | ||
} | ||
var _ary = [], | ||
_validate = _handler.validate; | ||
if(zn.is(_validate, 'string')){ | ||
_ary.push(_validate); | ||
} | ||
if(zn.is(_validate, 'array')){ | ||
_ary = _validate; | ||
} | ||
for(var i=0, _len = _ary.length; i < _len; i++){ | ||
if(!_request.session.getItem(_ary[i])){ | ||
return response.sessionTimeout('Session ' + _ary[i] + ' is invalid.'); | ||
} | ||
} | ||
} | ||
@@ -58,0 +75,0 @@ zn._request = _request; |
@@ -24,3 +24,3 @@ /** | ||
return zn.Class({ | ||
events: ['end','finish'], | ||
events: ['end', 'finish', 'timeout'], | ||
properties: { | ||
@@ -50,5 +50,5 @@ request: null, | ||
this._serverResponse = value; | ||
value.setTimeout(12000, function (){ | ||
value.end('[ request timeout ]'); | ||
}); | ||
value.on('timeout', function (){ | ||
this.fire('timeout'); | ||
}.bind(this)); | ||
value.on('finish', function (){ | ||
@@ -95,21 +95,36 @@ this.fire('finish'); | ||
}, | ||
setTimeout: function (timeout){ | ||
var _timeout = timeout || this._context._config.timeout || 12000; | ||
this._serverResponse.setTimeout(_timeout, function (){ | ||
this.error('Error: Request handler timeout.'); | ||
}.bind(this)); | ||
return this; | ||
}, | ||
write: function(inData, inEncode){ | ||
var _req = this._request; | ||
var _callback = _req.getValue('callback'), | ||
_data = inData; | ||
if(typeof _data === 'object'){ | ||
_data = JSON.stringify(inData, null, ' '); | ||
} | ||
try { | ||
if(this._serverResponse.finished){ | ||
return; | ||
} | ||
var _req = this._request; | ||
var _callback = _req.getValue('callback'), | ||
_data = inData; | ||
if(typeof _data === 'object'){ | ||
_data = JSON.stringify(inData, null, ' '); | ||
} | ||
if(_callback){ | ||
_data = _callback+'('+_data+')'; | ||
this.contentType = 'JAVASCRIPT'; | ||
if(_callback){ | ||
_data = _callback+'('+_data+')'; | ||
this.contentType = 'JAVASCRIPT'; | ||
} | ||
this.writeHead(200, { | ||
'Content-Type': CONTENT_TYPE[this.contentType] | ||
}); | ||
this._serverResponse.write(_data, inEncode); | ||
zn._request = null; | ||
zn._response = null; | ||
} catch (err) { | ||
zn.error('Response write error: ' + JSON.stringify(err)); | ||
} | ||
this.writeHead(200, { | ||
'Content-Type': CONTENT_TYPE[this.contentType] | ||
}); | ||
this._serverResponse.write(_data, inEncode); | ||
zn._request = null; | ||
zn._response = null; | ||
}, | ||
@@ -123,4 +138,4 @@ writeContent: function (status, content, contentType){ | ||
}); | ||
this.end(content, _encode); | ||
this._serverResponse.write(content, _encode); | ||
this.end(); | ||
}, | ||
@@ -229,4 +244,4 @@ writePath: function (_path, _encoding){ | ||
}, | ||
end: function (inData, inEncode) { | ||
this._serverResponse.end(inData, inEncode); | ||
end: function () { | ||
this._serverResponse.end(); | ||
this.fire('end', this); | ||
@@ -233,0 +248,0 @@ }, |
@@ -98,3 +98,7 @@ /** | ||
fs.readdir(path, function(err, files){ | ||
if(err){ zn.error(err); return; } | ||
if(err){ | ||
zn.error(err); | ||
callback(applicationContext); | ||
return; | ||
} | ||
var _queue = zn.queue(); | ||
@@ -101,0 +105,0 @@ files.forEach(function(file){ |
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
6388086
317
10812
12
+ Addednodemailer@^2.6.4
+ Addedofficegen@^0.4.0
+ Addedxlsx@^0.8.0
+ Addedaddressparser@1.0.1(transitive)
+ Addedadler-32@1.3.1(transitive)
+ Addedarchiver@3.0.3(transitive)
+ Addedarchiver-utils@2.1.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedbuildmail@4.0.1(transitive)
+ Addedcfb@0.11.1(transitive)
+ Addedcodepage@1.15.0(transitive)
+ Addedcolors@0.6.2(transitive)
+ Addedcommander@12.1.0(transitive)
+ Addedcompress-commons@2.1.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcrc@3.8.0(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedcrc32-stream@3.0.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexit-on-epipe@1.0.1(transitive)
+ Addedfast-image-size@0.1.3(transitive)
+ Addedfrac@0.3.1(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhttpntlm@1.6.1(transitive)
+ Addedhttpreq@1.1.1(transitive)
+ Addediconv-lite@0.4.15(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedimmediate@3.0.6(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedip@1.1.9(transitive)
+ Addedjszip@3.10.1(transitive)
+ Addedlazystream@1.0.1(transitive)
+ Addedlibbase64@0.1.0(transitive)
+ Addedlibmime@3.0.0(transitive)
+ Addedlibqp@1.1.0(transitive)
+ Addedlie@3.3.0(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.difference@4.5.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.union@4.6.0(transitive)
+ Addedmailcomposer@4.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednodemailer@2.7.2(transitive)
+ Addednodemailer-direct-transport@3.3.2(transitive)
+ Addednodemailer-fetch@1.6.0(transitive)
+ Addednodemailer-shared@1.1.0(transitive)
+ Addednodemailer-smtp-pool@2.8.2(transitive)
+ Addednodemailer-smtp-transport@2.7.2(transitive)
+ Addednodemailer-wellknown@0.1.10(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedofficegen@0.4.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpako@1.0.11(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedreadable-stream@3.2.03.6.2(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedsmart-buffer@1.1.15(transitive)
+ Addedsmtp-connection@2.12.0(transitive)
+ Addedsocks@1.1.9(transitive)
+ Addedssf@0.8.2(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedunderscore@1.7.0(transitive)
+ Addedvoc@1.2.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxlsx@0.8.8(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
+ Addedzip-stream@2.1.3(transitive)