Răsfoiți Sursa

actually store the skin in store_skin, fixes #108; pipe skins & capes through lwip before saving, fixes #121

jomo 10 ani în urmă
părinte
comite
288657107e
3 a modificat fișierele cu 22 adăugiri și 17 ștergeri
  1. 17 9
      lib/helpers.js
  2. 3 6
      lib/networking.js
  3. 2 2
      test/test.js

+ 17 - 9
lib/helpers.js

@@ -32,6 +32,7 @@ function store_skin(rid, userId, profile, cache_details, callback) {
         logging.log(rid, "new skin hash:", skin_hash);
         var facepath = path.join(__dirname, "..", config.faces_dir, skin_hash + ".png");
         var helmpath = path.join(__dirname, "..", config.helms_dir, skin_hash + ".png");
+        var skinpath = path.join(__dirname, "..", config.skins_dir, skin_hash + ".png");
         fs.exists(facepath, function(exists) {
           if (exists) {
             logging.log(rid, "skin already exists, not downloading");
@@ -41,16 +42,23 @@ function store_skin(rid, userId, profile, cache_details, callback) {
               if (err1 || !img) {
                 callback(err1, null);
               } else {
-                skins.extract_face(img, facepath, function(err2) {
-                  if (err2) {
-                    logging.error(rid, err2.stack);
-                    callback(err2, null);
+                skins.save_image(img, skinpath, function(skin_err) {
+                  if (skin_err) {
+                    logging.error(rid, skin_err);
+                    callback(skin_err, null);
                   } else {
-                    logging.debug(rid, "face extracted");
-                    skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
-                      logging.debug(rid, "helm extracted");
-                      logging.debug(rid, helmpath);
-                      callback(err3, skin_hash);
+                    skins.extract_face(img, facepath, function(err2) {
+                      if (err2) {
+                        logging.error(rid, err2.stack);
+                        callback(err2, null);
+                      } else {
+                        logging.debug(rid, "face extracted");
+                        skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
+                          logging.debug(rid, "helm extracted");
+                          logging.debug(rid, helmpath);
+                          callback(err3, skin_hash);
+                        });
+                      }
                     });
                   }
                 });

+ 3 - 6
lib/networking.js

@@ -2,7 +2,7 @@ var http_code = require("http").STATUS_CODES;
 var logging = require("./logging");
 var request = require("request");
 var config = require("./config");
-var fs = require("fs");
+var skins = require("./skins");
 
 var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/";
 var skins_url = "https://skins.minecraft.net/MinecraftSkins/";
@@ -176,11 +176,8 @@ exp.save_texture = function(rid, tex_hash, outpath, callback) {
         logging.error(rid, "error while downloading texture");
         callback(err, response, null);
       } else {
-        fs.writeFile(outpath, img, "binary", function(fs_err) {
-          if (fs_err) {
-            logging.error(rid, "error:", fs_err.stack);
-          }
-          callback(fs_err, response, img);
+        skins.save_image(img, outpath, function(img_err) {
+          callback(img_err, response, img);
         });
       }
     });

+ 2 - 2
test/test.js

@@ -448,7 +448,7 @@ describe("Crafatar", function() {
       "skin with existing username": {
         url: "http://localhost:3000/skins/jeb_",
         etag: '"a846b82963"',
-        crc32: 110922424
+        crc32: 26500336
       },
       "skin with not existing username": {
         url: "http://localhost:3000/skins/0",
@@ -468,7 +468,7 @@ describe("Crafatar", function() {
       "skin with existing uuid": {
         url: "http://localhost:3000/skins/853c80ef3c3749fdaa49938b674adae6",
         etag: '"a846b82963"',
-        crc32: 110922424
+        crc32: 26500336
       },
       "skin with not existing uuid": {
         url: "http://localhost:3000/skins/00000000000000000000000000000000",