Przeglądaj źródła

Move extraction logic

Jake 10 lat temu
rodzic
commit
caf7c731da
2 zmienionych plików z 15 dodań i 15 usunięć
  1. 13 3
      modules/helpers.js
  2. 2 12
      modules/networking.js

+ 13 - 3
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);
+                  });
+                }
+              });
             }
           });
         }

+ 2 - 12
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);
     }
   });
 };