From 8b6f268bc071a1a7c6474e2a228bbdba8fa4165c Mon Sep 17 00:00:00 2001 From: Jose Umberto Date: Wed, 28 Jun 2017 18:20:36 -0300 Subject: [PATCH] Cache problem was resolved --- src/client/controllers/temporal.js | 5 ++-- src/client/controllers/tvi.js | 2 -- src/client/controllers/tviSupervisor.js | 3 ++- src/server/config.js | 1 + src/server/controllers/kml.js | 2 +- src/server/controllers/login.js | 6 ++--- src/server/controllers/proxy.js | 1 - src/server/controllers/tms.js | 5 ++-- src/server/middleware/cache.js | 33 +++++++++++++++++++++++++ 9 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/client/controllers/temporal.js b/src/client/controllers/temporal.js index f448a93..cb78e95 100644 --- a/src/client/controllers/temporal.js +++ b/src/client/controllers/temporal.js @@ -201,6 +201,7 @@ Application.controller('temporalController', function($rootScope, $scope, $locat var lat = $scope.point.lat; var county = $scope.point.county; var url = window.location.origin+window.location.pathname + console.log(url); $window.open(url+"service/kml?longitude="+lon+"&latitude="+lat+"&county="+county); } @@ -234,8 +235,8 @@ Application.controller('temporalController', function($rootScope, $scope, $locat initFormViewVariables(); generateOptionYears($scope.config.initialYear, $scope.config.finalYear); - createModisChart() - createPrecipitationChart() + createModisChart(); + createPrecipitationChart(); generateMaps(); $scope.counter = 0; diff --git a/src/client/controllers/tvi.js b/src/client/controllers/tvi.js index 4d898c8..d626359 100644 --- a/src/client/controllers/tvi.js +++ b/src/client/controllers/tvi.js @@ -2,7 +2,6 @@ Application.controller('TviController', function($rootScope, $scope, $location, $window, requester, util, $interval, $timeout) { - requester._get('login/user', function(result) { if(!result.name) { $location.path('login'); @@ -65,7 +64,6 @@ Application.controller('TviController', function($rootScope, $scope, $location, requester._get('points/next-point', function(data) { $scope.data = data; - console.log('ola', data.total, data.current) $rootScope.total = data.total; $rootScope.current = data.current; $rootScope.count = data.count; diff --git a/src/client/controllers/tviSupervisor.js b/src/client/controllers/tviSupervisor.js index 56a60b8..8f85ac2 100644 --- a/src/client/controllers/tviSupervisor.js +++ b/src/client/controllers/tviSupervisor.js @@ -67,11 +67,12 @@ Application.controller('tviSuper', function($rootScope, $scope, $location, $wind }); } $scope.getKml = function(){ - + console.log('oi') var lon = $scope.data.lon; var lat = $scope.data.lat; var county = $scope.data.county; var url = window.location.origin+window.location.pathname + console.log('oi') $window.open(url+"service/kml?longitude="+lon+"&latitude="+lat+"&county="+county); } diff --git a/src/server/config.js b/src/server/config.js index dbe5077..113f68d 100644 --- a/src/server/config.js +++ b/src/server/config.js @@ -7,6 +7,7 @@ module.exports = function(app) { "clientDir": appRoot + "/../client", "langDir": appRoot + "/lang", "logDir": appRoot + "/log/", + "imgs": appRoot + "/images/", "redis": { "host": "localhost", "port": 6379 diff --git a/src/server/controllers/kml.js b/src/server/controllers/kml.js index 0f8366d..9d23be8 100644 --- a/src/server/controllers/kml.js +++ b/src/server/controllers/kml.js @@ -17,7 +17,7 @@ module.exports = function(app) { coordinates: lon+","+lat }); response.setHeader('Content-type', 'text/xml') - response.setHeader('Content-disposition', 'attachment; filename=aquivo.kml'); + response.setHeader('Content-disposition', 'attachment; filename=arquivo.kml'); response.write(content); response.end() }); diff --git a/src/server/controllers/login.js b/src/server/controllers/login.js index 1fe473a..e5c6513 100644 --- a/src/server/controllers/login.js +++ b/src/server/controllers/login.js @@ -71,9 +71,9 @@ module.exports = function(app) { app.on('socket-disconnect', function(socket) { - points.update({"_id": socket.request.session.currentPointId}, { $inc: { underInspection: -1}}, function(point) { - - }); + points.update({"_id": socket.request.session.currentPointId}, { $inc: { underInspection: -1}}, function(point) { + + }); }); return Login; diff --git a/src/server/controllers/proxy.js b/src/server/controllers/proxy.js index 2ffe1d6..9c0efe0 100644 --- a/src/server/controllers/proxy.js +++ b/src/server/controllers/proxy.js @@ -65,7 +65,6 @@ module.exports = function(app) { var longitude = request.param('longitude'); longitude = '-49.6582'; latitude = '-16.4382'; - console.log('longitude latitude',latitude, longitude); var Url = "http://maps.lapig.iesa.ufg.br/time-series/TRMM_PRECIPITATION/values?_dc=1497123621159&longitude="+longitude+"&latitude="+latitude+"&mode=series&radius=" requester({ diff --git a/src/server/controllers/tms.js b/src/server/controllers/tms.js index 931b623..e74049f 100644 --- a/src/server/controllers/tms.js +++ b/src/server/controllers/tms.js @@ -43,8 +43,7 @@ module.exports = function(app) { url = url.replace(id,mapid); cache.get(path, function(img) { - - if(img){ + if(img){ Internal.enhanceAndResponse(img, response) } else { var img = new Buffer([]); @@ -69,7 +68,7 @@ module.exports = function(app) { var data = new Buffer(data); img = Buffer.concat([img, data]) - }).on('end', function(data) { + }).on('end', function(data) { Internal.enhanceAndResponse(img, response) if(img.length > 0) { cache.set(path, img) diff --git a/src/server/middleware/cache.js b/src/server/middleware/cache.js index 0f63343..2b232c5 100644 --- a/src/server/middleware/cache.js +++ b/src/server/middleware/cache.js @@ -2,7 +2,10 @@ var util = require('util') , redis = require('redis') , request = require('request') , async = require('async'); +var fs = require('fs'); +var exec = require('child_process').exec; +var count = 0 module.exports = function(app) { var config = app.config; @@ -11,6 +14,17 @@ module.exports = function(app) { var Cache = {}; Cache.get = function(cacheKey, callback) { + var path = config.imgs+cacheKey+'/'; + var img = cacheKey.slice(24, 29); + fs.readFile(path+img, function (err,data) { + if (!err && data) { + callback(data); + }else{ + callback(undefined); + } + }); + + /* redisClient.get(cacheKey, function(err, data) { if(!err && data) { var bitmap = new Buffer(data,'base64'); @@ -19,11 +33,30 @@ module.exports = function(app) { callback(undefined); } }); + */ + }; Cache.set = function(cacheKey, data){ + cacheKey = cacheKey.substr(1); + exec('mkdir -p '+config.imgs+cacheKey, function(err, stdout, stderr){ + var path = config.imgs+cacheKey+'/'; + var img = cacheKey.slice(24, 29); + fs.writeFile(path+img, data, function(err) { + if(err) { + return console.log(err); + } + console.log("The file was saved!"); + }); + + }) + + + /* var img = new Buffer(data || '').toString('base64'); redisClient.set(cacheKey, img, function(){}); + */ + } Cache.del = function(keyPattern, data) {