From a07ca210d612956103cc22bb4eb292a1d79c91b0 Mon Sep 17 00:00:00 2001 From: jomo Date: Wed, 29 Oct 2014 21:23:36 +0100 Subject: [PATCH] fix undefined skins_dir, add http_timeout to config --- modules/config.js | 4 +++- modules/helpers.js | 3 +-- modules/networking.js | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/config.js b/modules/config.js index ec0d945..3d53f99 100644 --- a/modules/config.js +++ b/modules/config.js @@ -2,7 +2,9 @@ var config = { min_size: 0, // < 0 will (obviously) cause crash max_size: 512, // too big values might lead to slow response time or DoS default_size: 180, // size to be used when no size given - browser_cache_time: 3600 // seconds until browser will request image again + browser_cache_time: 3600,// seconds until browser will request image again + http_timeout: 1000, // ms until connection to mojang is dropped + skins_dir: 'skins/' // directory where skins are kept. should have trailing '/' }; module.exports = config; \ No newline at end of file diff --git a/modules/helpers.js b/modules/helpers.js index 367a5f1..515a9e1 100644 --- a/modules/helpers.js +++ b/modules/helpers.js @@ -4,7 +4,6 @@ var skins = require('./skins'); var fs = require('fs'); var valid_uuid = /^[0-9a-f]{32}$/; -var skins_dir = config.skins_dir; var exp = {}; @@ -42,7 +41,7 @@ exp.uuid_valid = function(uuid) { // 2: profile requested/found, skin downloaded from mojang servers // 3: profile requested/found, but it has no skin exp.get_avatar = function(uuid, size, callback) { - var filepath = skins_dir + uuid + ".png"; + var filepath = config.skins_dir + uuid + ".png"; if (fs.existsSync(filepath)) { skins.resize_img(filepath, size, function(result) { callback(null, 1, result); diff --git a/modules/networking.js b/modules/networking.js index a0c5c27..d4f6842 100644 --- a/modules/networking.js +++ b/modules/networking.js @@ -1,4 +1,5 @@ var request = require('request'); +var config = require('./config'); var skins = require('./skins'); var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/"; @@ -8,7 +9,7 @@ var exp = {}; exp.get_profile = function(uuid, callback) { request.get({ url: session_url + uuid, - timeout: 1000 // ms + timeout: config.http_timeout // ms }, function (error, response, body) { if (!error && response.statusCode == 200) { callback(null, JSON.parse(body)); @@ -36,7 +37,7 @@ exp.skin_file = function(url, outname, callback) { request.get({ url: url, encoding: null, // encoding must be null so we get a buffer - timeout: 1000 // ms + timeout: config.http_timeout // ms }, function (error, response, body) { if (!error && response.statusCode == 200) { skins.extract_face(body, outname, function() {