diff --git a/modules/cache.js b/modules/cache.js index a5912a5..0f6f1ca 100644 --- a/modules/cache.js +++ b/modules/cache.js @@ -1,6 +1,5 @@ var config = require("./config"); var redis = require("redis").createClient(); -var fs = require("fs"); var exp = {}; diff --git a/modules/helpers.js b/modules/helpers.js index f63a87a..16b0ea3 100644 --- a/modules/helpers.js +++ b/modules/helpers.js @@ -2,7 +2,6 @@ var networking = require('./networking'); var config = require('./config'); var cache = require('./cache'); var skins = require('./skins'); -var fs = require('fs'); var valid_uuid = /^[0-9a-f]{32}$/; var hash_pattern = /[0-9a-f]+$/; @@ -88,7 +87,7 @@ function get_image_hash(uuid, callback) { console.log("uuid not known or too old"); store_images(uuid, details, function(err, hash) { if (err) { - callback(err, -1, null); + callback(err, -1, details && details.h); } else { console.log("hash: " + hash); callback(null, (hash ? 2 : 3), hash); @@ -114,22 +113,20 @@ exp.uuid_valid = function(uuid) { exp.get_avatar = function(uuid, helm, size, callback) { console.log("\nrequest: " + uuid); get_image_hash(uuid, function(err, status, hash) { - if (err) { - callback(err, -1, null); + if (hash) { + var filepath = (helm ? config.helms_dir : config.faces_dir) + hash + ".png"; + skins.resize_img(filepath, size, function(img_err, result) { + if (img_err) { + callback(img_err, -1, null); + } else { + // we might have a hash although an error occured + // (e.g. Mojang servers not reachable, using outdated hash) + callback(err, (err ? -1 : status), result); + } + }); } else { - if (hash) { - var filepath = (helm ? config.helms_dir : config.faces_dir) + hash + ".png"; - skins.resize_img(filepath, size, function(err, result) { - if (err) { - callback(err, -1, null); - } else { - callback(null, status, result); - } - }); - } else { - // hash is null when uuid has no skin - callback(null, status, null); - } + // hash is null when uuid has no skin + callback(err, status, null); } }); diff --git a/routes/avatars.js b/routes/avatars.js index d0732e3..dba5ec3 100644 --- a/routes/avatars.js +++ b/routes/avatars.js @@ -1,9 +1,7 @@ -var networking = require('../modules/networking'); var helpers = require('../modules/helpers'); var router = require('express').Router(); var config = require('../modules/config'); var skins = require('../modules/skins'); -var fs = require('fs'); /* GET avatar request. */ router.get('/:uuid', function(req, res) { @@ -29,15 +27,20 @@ router.get('/:uuid', function(req, res) { console.log(uuid + " - " + status); if (err) { console.error(err); - handle_404(def); + if (image) { + console.warn("error occured, image found anyway"); + sendimage(200, status, image); + } else { + handle_404(def); + } } else if (status == 1 || status == 2) { sendimage(200, status == 1, image); } else if (status == 3) { handle_404(def); } else { - console.error("wat"); - console.error(err); - console.error(status); + console.error("unexpected error/status"); + console.error("error: " + err); + console.error("status: " + status); handle_404(def); } });