Comparing version 0.1.16 to 0.1.17
@@ -12,2 +12,4 @@ /** | ||
app_tag_on: true, //是否支持标签功能 | ||
url_resource_on: false, //是否监听静态资源类请求 | ||
url_resource_suffix: 'js,css,png,jpg,jpeg,gif,ico,cur,swf'.split(","), | ||
url_route_on: true, //开启自定义路由功能 | ||
@@ -14,0 +16,0 @@ url_html_suffix: ".html", //url后缀,这样可以做到伪静态,对搜索引擎更友好 |
@@ -9,2 +9,3 @@ /** | ||
app_begin: [], | ||
resource_check: ['CheckResource'], | ||
route_check: ['CheckRoute'], | ||
@@ -11,0 +12,0 @@ url_dispatch: [], |
@@ -169,2 +169,6 @@ /** | ||
var instance = App(http); | ||
//如果是静态资源类请求,则结束后续的执行 | ||
if (http.is_resource_request) { | ||
return true; | ||
}; | ||
tag('app_begin', http); | ||
@@ -171,0 +175,0 @@ http.usage.appBegin = G(); |
@@ -35,30 +35,37 @@ var url = require("url"); | ||
this.http.pathname = pathname; | ||
//是否使用自定义路由 | ||
if (!this.routerCheck()) { | ||
var paths = pathname.split("/"); | ||
var groupList = (C('app_group_list') || []).map(function(item){ | ||
return item.toLowerCase(); | ||
}); | ||
if (groupList.length) { | ||
if (groupList.indexOf((paths[0] + "").toLowerCase()) > -1) { | ||
group = paths.shift(); | ||
}; | ||
//是静态资源类请求 | ||
if (this.resourceCheck()) { | ||
return true; | ||
}; | ||
//使用自定义路由 | ||
if (this.routeCheck()) { | ||
return true; | ||
}; | ||
//使用默认路由 | ||
var paths = pathname.split("/"); | ||
//将group list变为小写 | ||
var groupList = (C('app_group_list') || []).map(function(item){ | ||
return item.toLowerCase(); | ||
}); | ||
if (groupList.length) { | ||
if (groupList.indexOf((paths[0] + "").toLowerCase()) > -1) { | ||
group = paths.shift(); | ||
}; | ||
var deny = C('app_group_deny') || []; | ||
if (group && deny.length) { | ||
if (deny.indexOf(_group) > -1) { | ||
throw_error("favicon.ico", this.http); | ||
}; | ||
}; | ||
var deny = C('app_group_deny') || []; | ||
if (group && deny.length) { | ||
if (deny.indexOf(group) > -1) { | ||
throw_error(group + " is not allowed", this.http); | ||
}; | ||
controller = paths.shift(); | ||
action = paths.shift(); | ||
if (paths.length) { | ||
for(var i = 0,length = Math.ceil(paths.length)/2; i < length; i++){ | ||
this.http.get[paths[i * 2]] = paths[i * 2 + 1] || ""; | ||
} | ||
}; | ||
this.http.group = Dispatcher.getGroup(group); | ||
this.http.controller = Dispatcher.getController(controller); | ||
this.http.action = Dispatcher.getAction(action); | ||
}; | ||
controller = paths.shift(); | ||
action = paths.shift(); | ||
if (paths.length) { | ||
for(var i = 0,length = Math.ceil(paths.length)/2; i < length; i++){ | ||
this.http.get[paths[i * 2]] = paths[i * 2 + 1] || ""; | ||
} | ||
}; | ||
this.http.group = Dispatcher.getGroup(group); | ||
this.http.controller = Dispatcher.getController(controller); | ||
this.http.action = Dispatcher.getAction(action); | ||
return true; | ||
@@ -70,4 +77,11 @@ }, | ||
*/ | ||
routerCheck: function(){ | ||
routeCheck: function(){ | ||
return tag('route_check', this.http); | ||
}, | ||
/** | ||
* 静态资源类请求 | ||
* @return {[type]} [description] | ||
*/ | ||
resourceCheck: function(){ | ||
return tag('resource_check', this.http); | ||
} | ||
@@ -74,0 +88,0 @@ } |
@@ -367,3 +367,3 @@ var util = require('util'); | ||
/** | ||
* 解析参数 | ||
* 解析参数,在this.promise后执行 | ||
* @param {[type]} options [description] | ||
@@ -373,2 +373,3 @@ * @return promise [description] | ||
parseOptions: function(options){ | ||
var self = this; | ||
options = extend(this.options, options); | ||
@@ -383,3 +384,5 @@ // 查询过后清空sql表达式组装 避免影响下次查询 | ||
options.table = this.getTableName(); | ||
promise = get_promise(this.fields["_field"]); | ||
promise = this.promise.then(function(){ | ||
return self.fields["_field"]; | ||
}); | ||
} | ||
@@ -391,3 +394,2 @@ //数据表别名 | ||
options.modal = this.name; | ||
var self = this; | ||
return promise.then(function(fields){ | ||
@@ -440,3 +442,3 @@ // 字段类型验证 | ||
/** | ||
* 对插入到数据库中的数据进行处理 | ||
* 对插入到数据库中的数据进行处理,要在parseOptions后执行 | ||
* @param {[type]} data [description] | ||
@@ -450,3 +452,3 @@ * @return {[type]} [description] | ||
var val = data[key]; | ||
if (!this.fields["_field"].indexOf(key) > -1) { | ||
if (this.fields["_field"].indexOf(key) === -1) { | ||
delete data[key]; | ||
@@ -502,3 +504,5 @@ }else if(is_scalar(val)){ | ||
add: function(data, options, replace){ | ||
if (!data) { | ||
//copy data | ||
data = extend({}, data); | ||
if (is_empty(data)) { | ||
if (this._data) { | ||
@@ -512,5 +516,5 @@ data = this._data; | ||
}; | ||
data = this.parseData(data); | ||
var self = this; | ||
return this.parseOptions(options).then(function(options){ | ||
data = self.parseData(data); | ||
data = self._beforeInsert(data, options); | ||
@@ -523,9 +527,8 @@ //如果_beforeInsert返回false,则直接返回 | ||
//获取插入的ID | ||
return self.db.getLastInsID().then(function(id){ | ||
if (id) { | ||
data[self.getPk()] = id; | ||
} | ||
self._afterInsert(data, options); | ||
return id; | ||
}) | ||
var id = self.db.getLastInsertId(); | ||
if (id) { | ||
data[self.getPk()] = id; | ||
}; | ||
self._afterInsert(data, options); | ||
return id; | ||
}); | ||
@@ -548,3 +551,3 @@ }); | ||
return self.db.insertAll(data, options, replace).then(function(){ | ||
return self.db.getLastInsID(); | ||
return self.db.getLastInsertId(); | ||
}) | ||
@@ -597,2 +600,3 @@ }) | ||
update: function(data, options){ | ||
data = extend({}, data); | ||
if (is_empty(data)) { | ||
@@ -607,5 +611,5 @@ if (this._data) { | ||
}; | ||
data = this.parseData(data); | ||
var self = this; | ||
return this.parseOptions(options).then(function(options){ | ||
data = self.parseData(data); | ||
if (self._beforeUpdate(data, options) === false) { | ||
@@ -612,0 +616,0 @@ return false; |
@@ -13,2 +13,3 @@ /** | ||
}; | ||
this.lastInsertId = 0; | ||
}, | ||
@@ -77,2 +78,3 @@ /** | ||
} | ||
self.lastInsertId = ret.data.insertId; | ||
return ret.data.affectedRows || 0; | ||
@@ -145,14 +147,9 @@ }) | ||
/** | ||
* 获取最后插入的ID | ||
* 获取最后插入的id | ||
* @return {[type]} [description] | ||
*/ | ||
getLastInsID: function(){ | ||
return this.query("SELECT LAST_INSERT_ID()").then(function(data){ | ||
if (data) { | ||
return data[0][Object.keys(data[0])]; | ||
}; | ||
return 0; | ||
}); | ||
getLastInsertId: function(){ | ||
return this.lastInsertId; | ||
} | ||
} | ||
}); |
@@ -18,4 +18,4 @@ var path = require("path"); | ||
}; | ||
//靜態資源的根目錄, 用於靜態資源也走THINKJS的處理 | ||
if (global.RESOURCE_PATH) { | ||
//静态资源文件的跟目录 | ||
if (global.RESOURCE_PATH === undefined) { | ||
global.RESOURCE_PATH = ""; | ||
@@ -22,0 +22,0 @@ }; |
@@ -7,10 +7,7 @@ /** | ||
return { | ||
/*init: function(http){ | ||
this.super("init", http); | ||
}*/ | ||
indexAction: function(){ | ||
this.end("hello, thinkjs!"); | ||
//this.display(); //render Home/index_index.html file | ||
//render Tpl/Home/index_index.html file | ||
this.display(); | ||
} | ||
} | ||
}); |
{ | ||
"name": "thinkjs", | ||
"description": "thinkphp web framework for nodejs", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
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
169273
56
5061
28