From 288657107e0ce15f9d50de0b3be6236da0454629 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 28 May 2015 01:32:29 +0200 Subject: [PATCH] actually store the skin in store_skin, fixes #108; pipe skins & capes through lwip before saving, fixes #121 --- lib/helpers.js | 26 +++++++++++++++++--------- lib/networking.js | 9 +++------ test/test.js | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index c13629d..73a5967 100644 --- a/lib/helpers.js +++ b/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); + }); + } }); } }); diff --git a/lib/networking.js b/lib/networking.js index b1d46f3..31c506d 100644 --- a/lib/networking.js +++ b/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); }); } }); diff --git a/test/test.js b/test/test.js index 5949863..2769732 100644 --- a/test/test.js +++ b/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",