this is a better fix for #48

This commit is contained in:
jomo 2015-01-04 05:03:45 +01:00
parent 3a0a23e5b5
commit 9affb00576

View File

@ -24,30 +24,20 @@ function store_images(uuid, details, callback) {
} else { } else {
if (skin_url) { if (skin_url) {
logging.log(uuid + " " + skin_url); logging.log(uuid + " " + skin_url);
var hash = get_hash(skin_url);
// set file paths // set file paths
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png"; var hash = get_hash(skin_url);
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png"; if (details && details.hash == hash) {
// hash hasn't changed
// make sure the file is still there
fs.exists(facepath, function(err, face_exists) {
if (err) {
logging.error(uuid + "error: " + err);
}
var exists = !err && face_exists;
if (exists && details && details.hash == hash) {
logging.log(uuid + " hash has not changed"); logging.log(uuid + " hash has not changed");
cache.update_timestamp(uuid, hash); cache.update_timestamp(uuid, hash);
callback(null, hash); callback(null, hash);
} else {
if (details && details.hash && !exists) {
logging.warn(uuid + " File was deleted! Downloading again.");
} else { } else {
// hash has changed // hash has changed
logging.log(uuid + " new hash: " + hash); logging.log(uuid + " new hash: " + hash);
} var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
if (exists) { var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
if (fs.existsSync(facepath)) {
logging.log(uuid + " Avatar already exists, not downloading"); logging.log(uuid + " Avatar already exists, not downloading");
cache.save_hash(uuid, hash); cache.save_hash(uuid, hash);
callback(null, hash); callback(null, hash);
@ -76,7 +66,6 @@ function store_images(uuid, details, callback) {
}); });
} }
} }
});
} else { } else {
// profile found, but has no skin // profile found, but has no skin
cache.save_hash(uuid, null); cache.save_hash(uuid, null);