mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
re-add checking for existing file before downloading
This commit is contained in:
parent
8cea2ed65f
commit
e01cff53b2
@ -35,6 +35,11 @@ function store_images(uuid, details, callback) {
|
||||
logging.log(uuid + " new hash: " + hash);
|
||||
var facepath = __dirname + '/../' + config.faces_dir + hash + ".png";
|
||||
var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png";
|
||||
|
||||
if (fs.existsSync(facepath)) {
|
||||
logging.log(uuid + " Avatar already exists, not downloading");
|
||||
callback(null, hash);
|
||||
} else {
|
||||
// download skin
|
||||
networking.get_skin(skin_url, function(err, img) {
|
||||
if (err || !img) {
|
||||
@ -45,9 +50,11 @@ function store_images(uuid, details, callback) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
logging.log(facepath + " face extracted");
|
||||
logging.log(uuid + " face extracted");
|
||||
logging.debug(facepath);
|
||||
skins.extract_helm(facepath, img, helmpath, function(err) {
|
||||
logging.log(helmpath + " helm extracted.");
|
||||
logging.log(uuid + " helm extracted");
|
||||
logging.debug(helmpath);
|
||||
cache.save_hash(uuid, hash);
|
||||
callback(err, hash);
|
||||
});
|
||||
@ -56,6 +63,7 @@ function store_images(uuid, details, callback) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// profile found, but has no skin
|
||||
cache.save_hash(uuid, null);
|
||||
@ -144,22 +152,4 @@ 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.get_skin(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;
|
||||
@ -108,7 +108,8 @@ exp.get_skin = function(url, callback) {
|
||||
}, function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
// skin downloaded successfully
|
||||
logging.log(url + " skin downloaded");
|
||||
logging.log("downloaded skin");
|
||||
logging.debug(url);
|
||||
callback(null, body);
|
||||
} else {
|
||||
if (error) {
|
||||
|
||||
26
test/test.js
26
test/test.js
@ -133,23 +133,6 @@ describe('Crafatar', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should already have the files / not download", function(done) {
|
||||
|
||||
// FIXME: implement & remove this line
|
||||
throw("Please re-implement this and add a new test");
|
||||
|
||||
|
||||
assert.doesNotThrow(function() {
|
||||
fs.openSync("face.png", "w");
|
||||
fs.openSync("helm.png", "w");
|
||||
networking.get_skin("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(err, img) {
|
||||
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
||||
fs.unlinkSync("face.png");
|
||||
fs.unlinkSync("helm.png");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it("should default to Alex", function(done) {
|
||||
assert.strictEqual(skins.default_skin("ec561538f3fd461daff5086b22154bce"), "alex");
|
||||
done();
|
||||
@ -218,13 +201,4 @@ describe('Crafatar', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
try {
|
||||
// these files could be here if a test failed
|
||||
fs.unlinkSync("face.png");
|
||||
fs.unlinkSync("helm.png");
|
||||
} catch(e){}
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user