Rewrite skin support

This commit is contained in:
Jake
2014-11-29 12:21:35 -06:00
parent caf7c731da
commit a4c11f396f
5 changed files with 29 additions and 49 deletions

View File

@@ -16,7 +16,7 @@ function connect_redis() {
}
redis.on("ready", function() {
logging.log("Redis connection established.");
if(process.env.HEROKU) {
if(process.env.HEROKU || true) {
logging.log("Running on heroku, flushing redis");
redis.flushall();
}

View File

@@ -36,7 +36,7 @@ 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, img) {
networking.skin_file(skin_url, facepath, function(err, img) {
if (err) {
callback(err, null);
} else {
@@ -143,4 +143,22 @@ exp.get_avatar = function(uuid, helm, size, callback) {
});
};
exp.get_skin = function(uuid, callback) {
logging.log("\nskin request: " + uuid);
exp.get_image_hash(uuid, function(err, status, hash) {
if (hash) {
var skinurl = "http://textures.minecraft.net/texture/" + hash;
networking.skin_file(skinurl, null, function(err, img) {
if (err) {
logging.log("\nerror while downloading skin");
callback(err, hash, null);
} else {
logging.log("\nreturning skin");
callback(null, hash, img);
}
});
}
});
};
module.exports = exp;

View File

@@ -102,10 +102,10 @@ exp.get_skin_url = function(uuid, callback) {
// stores face image as +facename+
// stores helm image as +helmname+
// callback contains error
exp.skin_file = function(url, facename, helmname, callback) {
if (fs.existsSync(facename) && fs.existsSync(facename)) {
exp.skin_file = function(url, facename, callback) {
if (facename && fs.existsSync(facename)) {
logging.log("Images already exist, not downloading.");
callback(null);
callback(null, null);
return;
}
request.get({
@@ -116,7 +116,7 @@ exp.skin_file = function(url, facename, helmname, callback) {
if (!error && response.statusCode == 200) {
// skin downloaded successfully
logging.log(url + " skin downloaded");
callback(error, body);
callback(null, body);
} else {
if (error) {
logging.error("Error downloading '" + url + "': " + error);