Move extraction logic

This commit is contained in:
Jake 2014-11-29 10:55:51 -06:00
parent 2cc7b455af
commit caf7c731da
2 changed files with 15 additions and 15 deletions

View File

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

View File

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