diff --git a/modules/helpers.js b/modules/helpers.js index 5bb5df3..963042e 100644 --- a/modules/helpers.js +++ b/modules/helpers.js @@ -36,12 +36,22 @@ function store_images(uuid, details, callback) { var facepath = __dirname + '/../' + config.faces_dir + hash + ".png"; var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png"; // download skin, extract face/helm - networking.skin_file(skin_url, facepath, helmpath, function(err) { + networking.skin_file(skin_url, facepath, helmpath, function(err, img) { if (err) { callback(err, null); } else { - cache.save_hash(uuid, hash); - callback(null, hash); + skins.extract_face(img, facepath, function(err) { + if (err) { + callback(err); + } else { + logging.log(facepath + " face extracted"); + skins.extract_helm(facepath, img, helmpath, function(err) { + logging.log(helmpath + " helm extracted."); + cache.save_hash(uuid, hash); + callback(err, hash); + }); + } + }); } }); } diff --git a/modules/networking.js b/modules/networking.js index 884e9d9..243e039 100644 --- a/modules/networking.js +++ b/modules/networking.js @@ -116,17 +116,7 @@ exp.skin_file = function(url, facename, helmname, callback) { if (!error && response.statusCode == 200) { // skin downloaded successfully logging.log(url + " skin downloaded"); - skins.extract_face(body, facename, function(err) { - if (err) { - callback(err); - } else { - logging.log(facename + " face extracted"); - skins.extract_helm(facename, body, helmname, function(err) { - logging.log(helmname + " helm extracted."); - callback(err); - }); - } - }); + callback(error, body); } else { if (error) { logging.error("Error downloading '" + url + "': " + error); @@ -143,7 +133,7 @@ exp.skin_file = function(url, facename, helmname, callback) { logging.error(body); error = "unknown error"; // Error needs to be set, otherwise null in callback } - callback(error); + callback(error, null); } }); };