|
|
@ -1,9 +1,11 @@ |
|
|
|
// validate inputs, convert types and apply defaults
|
|
|
|
// validate inputs, convert types and apply defaults
|
|
|
|
function sanitize( req ){ |
|
|
|
function sanitize( req, default_size){ |
|
|
|
|
|
|
|
|
|
|
|
var clean = req.clean || {}; |
|
|
|
var clean = req.clean || {}; |
|
|
|
var params= req.query; |
|
|
|
var params= req.query; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var default_size = default_size || 10; |
|
|
|
|
|
|
|
|
|
|
|
// ensure the input params are a valid object
|
|
|
|
// ensure the input params are a valid object
|
|
|
|
if( Object.prototype.toString.call( params ) !== '[object Object]' ){ |
|
|
|
if( Object.prototype.toString.call( params ) !== '[object Object]' ){ |
|
|
|
params = {}; |
|
|
|
params = {}; |
|
|
@ -14,7 +16,7 @@ function sanitize( req ){ |
|
|
|
if( !isNaN( size ) ){ |
|
|
|
if( !isNaN( size ) ){ |
|
|
|
clean.size = Math.min( Math.max( size, 1 ), 40 ); // max
|
|
|
|
clean.size = Math.min( Math.max( size, 1 ), 40 ); // max
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
clean.size = 10; // default
|
|
|
|
clean.size = default_size; // default
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
req.clean = clean; |
|
|
|
req.clean = clean; |
|
|
|