Fix README merge

This commit is contained in:
Jake
2014-11-20 20:02:36 -06:00
17 changed files with 4602 additions and 4497 deletions

View File

@@ -2,7 +2,7 @@ var config = require("./config");
var redis = null;
var fs = require("fs");
// sets up redis connection, calls clear_cache
function connect_redis() {
console.log("connecting to redis...");
if (process.env.REDISCLOUD_URL) {
@@ -13,8 +13,8 @@ function connect_redis() {
redis = require("redis").createClient();
}
redis.on("ready", function() {
console.log("Redis connection established. Flushing all data.");
redis.flushall();
console.log("Redis connection established.");
clear_cache();
});
redis.on("error", function (err) {
console.error(err);
@@ -24,7 +24,39 @@ function connect_redis() {
});
}
// flushes redis, deletes faces + helms
function clear_cache() {
console.log("Flushing redis");
redis.flushall();
console.log("Deleting all faces + helms...");
fs.readdir(config.faces_dir, function(err, files) {
if (err) {
console.error(err);
} else {
for (var i in files) {
var file = files[i];
if (file[0] != ".") {
// delete face file
fs.unlink(config.faces_dir + file, function(err){
if (err) {
console.error(err);
}
});
// delete helm file, we assume this exists as well
fs.unlink(config.helms_dir + file, function(err){
if (err) {
console.error(err);
}
});
}
}
}
});
}
// sets the date of the face file belonging to +hash+ to now
// the helms file is ignored because we only need 1 file to read/write from
function update_file_date(hash) {
if (hash) {
var path = config.faces_dir + hash + ".png";

View File

@@ -57,6 +57,7 @@ function store_images(uuid, details, callback) {
}
} else {
// profile found, but has no skin
cache.save_hash(uuid, null);
callback(null, null);
}
}
@@ -83,9 +84,10 @@ function skin_url(profile) {
// callback contains error, status, hash
// the status gives information about how the image was received
// -1: error
// 0: cached as null
// 1: found on disk
// 2: profile requested/found, skin downloaded from mojang servers
// 3: profile requested/found, but it has no skin
// 3: profile requested/found, but it has not changed or no skin
function get_image_hash(uuid, callback) {
cache.get_details(uuid, function(err, details) {
if (err) {
@@ -102,7 +104,7 @@ function get_image_hash(uuid, callback) {
callback(err, -1, details && details.hash);
} else {
console.log(uuid + " hash: " + hash);
callback(null, (hash ? 2 : 3), hash);
callback(null, (hash != (details && details.hash) ? 2 : 3), hash);
}
});
}

View File

@@ -36,7 +36,7 @@ exp.extract_helm = function(facefile, buffer, outname, callback) {
if (err) {
callback(err);
} else {
skin.crop(42, 8, 49, 15, function(err, helm_img) {
skin.crop(40, 8, 47, 15, function(err, helm_img) {
if (err) {
callback(err);
} else {