Fix bug parsing adjustment options when encoded in \x?? format
This commit is contained in:
@@ -115,11 +115,11 @@ function getWxWeatherData( location, callback ) {
|
|||||||
wind: parseInt( data.cc[0].wind[0].s[0] )
|
wind: parseInt( data.cc[0].wind[0].s[0] )
|
||||||
};
|
};
|
||||||
|
|
||||||
Cache.findOne( { location: location }, function( err, record ) {
|
getCache( {
|
||||||
|
key: "yesterdayHumidity",
|
||||||
if ( record && record.yesterdayHumidity !== null ) {
|
location: location
|
||||||
weather.yesterdayHumidity = record.yesterdayHumidity;
|
}, function( record ) {
|
||||||
}
|
weather.yesterdayHumidity = record.yesterdayHumidity;
|
||||||
|
|
||||||
// Return the data to the callback function if successful
|
// Return the data to the callback function if successful
|
||||||
callback( weather );
|
callback( weather );
|
||||||
@@ -163,11 +163,11 @@ function getWeatherData( location, callback ) {
|
|||||||
|
|
||||||
location = location.join( "," );
|
location = location.join( "," );
|
||||||
|
|
||||||
Cache.findOne( { location: location }, function( err, record ) {
|
getCache( {
|
||||||
|
key: "yesterdayHumidity",
|
||||||
if ( record && record.yesterdayHumidity !== null ) {
|
location: location
|
||||||
weather.yesterdayHumidity = record.yesterdayHumidity;
|
}, function( record ) {
|
||||||
}
|
weather.yesterdayHumidity = record.yesterdayHumidity;
|
||||||
|
|
||||||
// Return the data to the callback function if successful
|
// Return the data to the callback function if successful
|
||||||
callback( weather );
|
callback( weather );
|
||||||
@@ -205,6 +205,26 @@ function getYesterdayWeatherData( location, callback ) {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve cached record for a given location
|
||||||
|
// opt is defined as an object with two required items
|
||||||
|
// opt.location defines the location for the cache record
|
||||||
|
// opt.key defines the key to return for the location
|
||||||
|
function getCache( opt, callback ) {
|
||||||
|
|
||||||
|
// Find the cache entry for the provided location
|
||||||
|
Cache.findOne( { location: opt.location }, function( err, record ) {
|
||||||
|
|
||||||
|
// If a record is found for the provided key, return it
|
||||||
|
if ( record && record[ opt.key ] !== null ) {
|
||||||
|
callback( record[ opt.key ] );
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Otherwise return null indicating no match is found
|
||||||
|
callback( null );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
// Update weather cache record in the local database
|
// Update weather cache record in the local database
|
||||||
function updateCache( location, weather ) {
|
function updateCache( location, weather ) {
|
||||||
|
|
||||||
@@ -392,6 +412,9 @@ exports.getWeather = function( req, res ) {
|
|||||||
// Parse weather adjustment options
|
// Parse weather adjustment options
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// Parse data that may be encoded
|
||||||
|
adjustmentOptions = decodeURIComponent( adjustmentOptions.replace( /\\x/g, "%" ) );
|
||||||
|
|
||||||
// Reconstruct JSON string from deformed controller output
|
// Reconstruct JSON string from deformed controller output
|
||||||
adjustmentOptions = JSON.parse( "{" + adjustmentOptions + "}" );
|
adjustmentOptions = JSON.parse( "{" + adjustmentOptions + "}" );
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user