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,59 +24,48 @@ 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
logging.log(uuid + " hash has not changed");
cache.update_timestamp(uuid, hash);
callback(null, hash);
} else {
// hash has changed
logging.log(uuid + " new hash: " + hash);
var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
// make sure the file is still there if (fs.existsSync(facepath)) {
fs.exists(facepath, function(err, face_exists) { logging.log(uuid + " Avatar already exists, not downloading");
if (err) { cache.save_hash(uuid, hash);
logging.error(uuid + "error: " + err);
}
var exists = !err && face_exists;
if (exists && details && details.hash == hash) {
logging.log(uuid + " hash has not changed");
cache.update_timestamp(uuid, hash);
callback(null, hash); callback(null, hash);
} else { } else {
if (details && details.hash && !exists) { // download skin
logging.warn(uuid + " File was deleted! Downloading again."); networking.get_skin(skin_url, function(err, img) {
} else { if (err || !img) {
// hash has changed callback(err, null);
logging.log(uuid + " new hash: " + hash); } else {
} // extract face / helm
if (exists) { skins.extract_face(img, facepath, function(err) {
logging.log(uuid + " Avatar already exists, not downloading"); if (err) {
cache.save_hash(uuid, hash); callback(err);
callback(null, hash); } else {
} else { logging.log(uuid + " face extracted");
// download skin logging.debug(facepath);
networking.get_skin(skin_url, function(err, img) { skins.extract_helm(facepath, img, helmpath, function(err) {
if (err || !img) { logging.log(uuid + " helm extracted");
callback(err, null); logging.debug(helmpath);
} else { cache.save_hash(uuid, hash);
// extract face / helm callback(err, hash);
skins.extract_face(img, facepath, function(err) { });
if (err) { }
callback(err); });
} else { }
logging.log(uuid + " face extracted"); });
logging.debug(facepath);
skins.extract_helm(facepath, img, helmpath, function(err) {
logging.log(uuid + " helm extracted");
logging.debug(helmpath);
cache.save_hash(uuid, hash);
callback(err, hash);
});
}
});
}
});
}
} }
}); }
} else { } else {
// profile found, but has no skin // profile found, but has no skin
cache.save_hash(uuid, null); cache.save_hash(uuid, null);