Browse Source

latlon is a required field for reverse (updated _geo sanitizer) and added ability to filter by layers on /reverse

pull/89/head
Harish Krishna 10 years ago
parent
commit
7a8422025a
  1. 21
      sanitiser/_geo.js
  2. 6
      sanitiser/reverse.js

21
sanitiser/_geo.js

@ -1,8 +1,9 @@
// validate inputs, convert types and apply defaults
function sanitize( req ){
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( Object.prototype.toString.call( params ) !== '[object Object]' ){
@ -18,8 +19,8 @@ function sanitize( req ){
};
// lat
if (!isNaN(params.lat)) {
var lat = parseFloat( params.lat, 10 );
var lat = parseFloat( params.lat, 10 );
if (!isNaN(lat)) {
if( is_invalid_lat(lat) ){
return {
'error': true,
@ -27,11 +28,16 @@ function sanitize( req ){
};
}
clean.lat = lat;
} else if (latlon_is_required) {
return {
'error': true,
'message': 'missing param \'lat\': must be >-90 and <90'
};
}
// lon
if (!isNaN(params.lon)) {
var lon = parseFloat( params.lon, 10 );
var lon = parseFloat( params.lon, 10 );
if (!isNaN(lon)) {
if( is_invalid_lon(lon) ){
return {
'error': true,
@ -39,6 +45,11 @@ function sanitize( req ){
};
}
clean.lon = lon;
} else if (latlon_is_required) {
return {
'error': true,
'message': 'missing param \'lon\': must be >-180 and <180'
};
}
// zoom level

6
sanitiser/reverse.js

@ -2,7 +2,11 @@
var logger = require('../src/logger'),
_sanitize = require('../sanitiser/_sanitize'),
sanitiser = {
latlonzoom: require('../sanitiser/_geo'),
latlonzoom: function( req ) {
var geo = require('../sanitiser/_geo');
return geo(req, true);
},
layers: require('../sanitiser/_layers'),
size: function( req ) {
var size = require('../sanitiser/_size');
return size(req, 1);

Loading…
Cancel
Save