<commit_before>'use strict';

var uuid = require('node-uuid')
  , reader = require('./apkReader');

var HOUR = 3600000;

var androidUpdate = {}
  , expressApp
  , routePfx
  , links = [];

androidUpdate.updater = function (req, res){
  var name = req.body.pkgname
    , version = req.body.version
    , last = reader.last(name);
  if(last && last.version > version){
  	if(!links[name]){
  		links[name] = { 
  			url: routePfx + '/' + uuid.v4(),
  			timeoutId: setTimeout(function() {
  				var idx;
  				for(idx in expressApp.routes.get){
  					if(expressApp.routes.get[idx].path === links[name].url){
  					  expressApp.routes.get.splice(idx, 1);
  					  break;
  					}
  				}
  				links[name] = null;
  			}, 4 * HOUR)
  		};  		
  		expressApp.get(links[name].url, function(req, res){
  			res.download(last.filepath);
  		});
  		// hack to put this route at first
  		expressApp.routes.get.unshift(expressApp.routes.get.pop());
  	}
    console.log("have update\n" + links[name].url);
    res.send("have update\n" + links[name].url);
  } else {
    console.log("ok : no update " + name + " - " + version + " / " + last );
  	res.send(200);
  }
};


/**
 * Enable auto apk updater for provided Express application and route.
 * @param {@Object} app parent Express application
 * @param {@String} route route prefix for current updater
 * @param {@String} repoDir path for apk directory
 */
function enable(app, route, repoDir){
  expressApp = app;
  routePfx = route;
  if(repoDir){<commit_msg>Add version id in response<commit_after>'use strict';

var uuid = require('node-uuid')
  , reader = require('./apkReader');

var HOUR = 3600000;

var androidUpdate = {}
  , expressApp
  , routePfx
  , links = [];

androidUpdate.updater = function (req, res){
  var name = req.body.pkgname
    , version = req.body.version
    , last = reader.last(name);
  if(last && last.version > version){
  	if(!links[name]){
  		links[name] = { 
  			url: routePfx + '/' + uuid.v4(),
  			timeoutId: setTimeout(function() {
  				var idx;
  				for(idx in expressApp.routes.get){
  					if(expressApp.routes.get[idx].path === links[name].url){
  					  expressApp.routes.get.splice(idx, 1);
  					  break;
  					}
  				}
  				links[name] = null;
  			}, 4 * HOUR)
  		};  		
  		expressApp.get(links[name].url, function(req, res){
  			res.download(last.filepath);
  		});
  		// hack to put this route at first
  		expressApp.routes.get.unshift(expressApp.routes.get.pop());
  	}
    // console.log("have update\n" + links[name].url + "\n" + last.version);
    res.send("have update\n" + links[name].url + "\n" + last.version);
  } else {
    console.log("ok : no update " + name + " - " + version + " / " + last );
  	res.send(200);
  }
};


/**
 * Enable auto apk updater for provided Express application and route.
 * @param {@Object} app parent Express application
 * @param {@String} route route prefix for current updater
 * @param {@String} repoDir path for apk directory
 */
function enable(app, route, repoDir){
  expressApp = app;
  routePfx = route;
  if(repoDir){
{'fraction_non_alphanumeric': 0.1599479843953186, 'fraction_numerical': 0.008452535760728219, 'mean_word_length': 2.836658354114713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176583', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1101, 'n_words': 239}