Browse Source

Split geo sanitiser into geo_reverse and geo_search

Common functions are moved to geo_common. This is required to allow
separate behavior for search and reverse.
pull/230/head
Julian Simioni 9 years ago
parent
commit
0d23792591
  1. 40
      sanitiser/_geo_common.js
  2. 30
      sanitiser/_geo_reverse.js
  3. 30
      sanitiser/_geo_search.js
  4. 5
      sanitiser/reverse.js
  5. 2
      sanitiser/search.js

40
sanitiser/_geo.js → sanitiser/_geo_common.js

@ -1,36 +1,7 @@
/**
* helper sanitiser methods for geo parameters
*/
var util = require( 'util' ); var util = require( 'util' );
var isObject = require('is-object');
// validate inputs, convert types and apply defaults
module.exports = function sanitize( req, latlon_is_required ){
var clean = req.clean || {};
var params = req.query;
latlon_is_required = latlon_is_required || false;
// ensure the input params are a valid object
if( !isObject( params ) ){
params = {};
}
try {
sanitize_coord( 'lat', clean, params.lat, latlon_is_required );
sanitize_coord( 'lon', clean, params.lon, latlon_is_required );
sanitize_bbox(clean, params.bbox);
}
catch (err) {
return {
'error': true,
'message': err.message
};
}
req.clean = clean;
return { 'error': false };
};
/** /**
* Parse and validate bbox parameter * Parse and validate bbox parameter
@ -81,3 +52,8 @@ function sanitize_coord( coord, clean, param, latlon_is_required ) {
throw new Error( util.format( 'missing param \'%s\'', coord ) ); throw new Error( util.format( 'missing param \'%s\'', coord ) );
} }
} }
module.exports = {
sanitize_bbox: sanitize_bbox,
sanitize_coord: sanitize_coord
};

30
sanitiser/_geo_reverse.js

@ -0,0 +1,30 @@
var isObject = require('is-object');
var geo_common = require ('./_geo_common');
// validate inputs, convert types and apply defaults
module.exports = function sanitize( req ){
var clean = req.clean || {};
var params = req.query;
var latlon_is_required = true;
// ensure the input params are a valid object
if( !isObject( params ) ){
params = {};
}
try {
geo_common.sanitize_coord( 'lat', clean, params.lat, latlon_is_required );
geo_common.sanitize_coord( 'lon', clean, params.lon, latlon_is_required );
geo_common.sanitize_bbox(clean, params.bbox);
}
catch (err) {
return {
'error': true,
'message': err.message
};
}
req.clean = clean;
return { 'error': false };
};

30
sanitiser/_geo_search.js

@ -0,0 +1,30 @@
var isObject = require('is-object');
var geo_common = require ('./_geo_common');
// validate inputs, convert types and apply defaults
module.exports = function sanitize( req ){
var clean = req.clean || {};
var params = req.query;
var latlon_is_required = false;
// ensure the input params are a valid object
if( !isObject( params ) ){
params = {};
}
try {
geo_common.sanitize_coord( 'lat', clean, params.lat, latlon_is_required );
geo_common.sanitize_coord( 'lon', clean, params.lon, latlon_is_required );
geo_common.sanitize_bbox(clean, params.bbox);
}
catch (err) {
return {
'error': true,
'message': err.message
};
}
req.clean = clean;
return { 'error': false };
};

5
sanitiser/reverse.js

@ -1,9 +1,6 @@
var _sanitize = require('../sanitiser/_sanitize'), var _sanitize = require('../sanitiser/_sanitize'),
sanitiser = { sanitiser = {
latlonzoom: function( req ) { latlonzoom: require('../sanitiser/_geo_reverse'),
var geo = require('../sanitiser/_geo');
return geo(req, true);
},
layers: require('../sanitiser/_layers'), layers: require('../sanitiser/_layers'),
details: require('../sanitiser/_details'), details: require('../sanitiser/_details'),
size: require('../sanitiser/_size'), size: require('../sanitiser/_size'),

2
sanitiser/search.js

@ -6,7 +6,7 @@ var _sanitize = require('../sanitiser/_sanitize'),
layers: require('../sanitiser/_layers'), layers: require('../sanitiser/_layers'),
source: require('../sanitiser/_source'), source: require('../sanitiser/_source'),
details: require('../sanitiser/_details'), details: require('../sanitiser/_details'),
latlonzoom: require('../sanitiser/_geo') latlonzoom: require('../sanitiser/_geo_search')
}; };
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); }; var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };

Loading…
Cancel
Save