use outdated hash on network errors, fixes #5 🍺

This commit is contained in:
jomo
2014-11-02 05:15:38 +01:00
parent 9e46878932
commit b513883d93
3 changed files with 23 additions and 24 deletions

View File

@@ -1,6 +1,5 @@
var config = require("./config");
var redis = require("redis").createClient();
var fs = require("fs");
var exp = {};

View File

@@ -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);
}
});