|
@@ -16,11 +16,11 @@ function get_hash(url) {
|
|
|
}
|
|
|
|
|
|
function store_skin(rid, userId, profile, details, callback) {
|
|
|
- networking.get_skin_url(rid, userId, profile, function(url) {
|
|
|
- if (url) {
|
|
|
+ networking.get_skin_url(rid, userId, profile, function(err, url) {
|
|
|
+ if (!err && url) {
|
|
|
var skin_hash = get_hash(url);
|
|
|
if (details && details.skin === skin_hash) {
|
|
|
- cache.update_timestamp(rid, userId, skin_hash, function(err) {
|
|
|
+ cache.update_timestamp(rid, userId, skin_hash, false, function(err) {
|
|
|
callback(err, skin_hash);
|
|
|
});
|
|
|
} else {
|
|
@@ -41,9 +41,9 @@ function store_skin(rid, userId, profile, details, callback) {
|
|
|
logging.error(rid + err2.stack);
|
|
|
callback(err2, null);
|
|
|
} else {
|
|
|
- logging.log(rid + "face extracted");
|
|
|
+ logging.debug(rid + "face extracted");
|
|
|
skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
|
|
|
- logging.log(rid + "helm extracted");
|
|
|
+ logging.debug(rid + "helm extracted");
|
|
|
logging.debug(rid + helmpath);
|
|
|
callback(err3, skin_hash);
|
|
|
});
|
|
@@ -55,17 +55,17 @@ function store_skin(rid, userId, profile, details, callback) {
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
- callback(null, null);
|
|
|
+ callback(err, null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function store_cape(rid, userId, profile, details, callback) {
|
|
|
- networking.get_cape_url(rid, userId, profile, function(url) {
|
|
|
- if (url) {
|
|
|
+ networking.get_cape_url(rid, userId, profile, function(err, url) {
|
|
|
+ if (!err && url) {
|
|
|
var cape_hash = get_hash(url);
|
|
|
if (details && details.cape === cape_hash) {
|
|
|
- cache.update_timestamp(rid, userId, cape_hash, function(err) {
|
|
|
+ cache.update_timestamp(rid, userId, cape_hash, false, function(err) {
|
|
|
callback(err, cape_hash);
|
|
|
});
|
|
|
} else {
|
|
@@ -82,7 +82,7 @@ function store_cape(rid, userId, profile, details, callback) {
|
|
|
callback(err, null);
|
|
|
} else {
|
|
|
skins.save_image(img, capepath, function(err) {
|
|
|
- logging.log(rid + "cape saved");
|
|
|
+ logging.debug(rid + "cape saved");
|
|
|
callback(err, cape_hash);
|
|
|
});
|
|
|
}
|
|
@@ -91,7 +91,7 @@ function store_cape(rid, userId, profile, details, callback) {
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
- callback(null, null);
|
|
|
+ callback(err, null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -155,20 +155,30 @@ function store_images(rid, userId, details, type, callback) {
|
|
|
callback_for(userId, "cape", cache_err, null);
|
|
|
});
|
|
|
} else {
|
|
|
- // an error occured, not caching
|
|
|
+ // an error occured, not caching. we can try in 60 seconds
|
|
|
callback_for(userId, type, err, null);
|
|
|
}
|
|
|
} else {
|
|
|
- // no error and we have a profile or it's not a uuid
|
|
|
+ // no error and we have a profile (if it's a uuid)
|
|
|
store_skin(rid, userId, profile, details, function(err, skin_hash) {
|
|
|
- cache.save_hash(rid, userId, skin_hash, null, function(cache_err) {
|
|
|
- callback_for(userId, "skin", (err || cache_err), skin_hash);
|
|
|
- store_cape(rid, userId, profile, details, function(err, cape_hash) {
|
|
|
- cache.save_hash(rid, userId, skin_hash, cape_hash, function(cache_err) {
|
|
|
- callback_for(userId, "cape", (err || cache_err), cape_hash);
|
|
|
- });
|
|
|
+ if (err && !skin_hash) {
|
|
|
+ // an error occured, not caching. we can try in 60 seconds
|
|
|
+ callback_for(userId, "skin", err, null);
|
|
|
+ } else {
|
|
|
+ cache.save_hash(rid, userId, skin_hash, null, function(cache_err) {
|
|
|
+ callback_for(userId, "skin", (err || cache_err), skin_hash);
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ store_cape(rid, userId, profile, details, function(err, cape_hash) {
|
|
|
+ if (err && !cape_hash) {
|
|
|
+ // an error occured, not caching. we can try in 60 seconds
|
|
|
+ callback_for(userId, "cape", (err || cache_err), cape_hash);
|
|
|
+ } else {
|
|
|
+ cache.save_hash(rid, userId, undefined, cape_hash, function(cache_err) {
|
|
|
+ callback_for(userId, "cape", (err || cache_err), cape_hash);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -186,7 +196,7 @@ exp.id_valid = function(userId) {
|
|
|
return valid_user_id.test(userId);
|
|
|
};
|
|
|
|
|
|
-// decides whether to get an image from disk or to download it
|
|
|
+// decides whether to get a +type+ image for +userId+ from disk or to download it
|
|
|
// callback contains error, status, hash
|
|
|
// the status gives information about how the image was received
|
|
|
// -1: "error"
|
|
@@ -196,11 +206,11 @@ exp.id_valid = function(userId) {
|
|
|
// 3: "checked" - profile re-downloaded (was too old), but it has either not changed or has no skin
|
|
|
exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
cache.get_details(userId, function(err, details) {
|
|
|
- var cached_hash = details !== null ? (type === "skin" ? details.skin : details.cape) : null;
|
|
|
+ var cached_hash = (details !== null) ? (type === "skin" ? details.skin : details.cape) : null;
|
|
|
if (err) {
|
|
|
callback(err, -1, null);
|
|
|
} else {
|
|
|
- if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
|
|
+ if (details && details[type] !== undefined && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
|
|
// use cached image
|
|
|
logging.log(rid + "userId cached & recently updated");
|
|
|
callback(null, (cached_hash ? 1 : 0), cached_hash);
|
|
@@ -215,7 +225,9 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|
|
if (err) {
|
|
|
// we might have a cached hash although an error occured
|
|
|
// (e.g. Mojang servers not reachable, using outdated hash)
|
|
|
- callback(err, -1, details && cached_hash);
|
|
|
+ cache.update_timestamp(rid, userId, cached_hash, true, function(err2) {
|
|
|
+ callback(err2 || err, -1, details && cached_hash);
|
|
|
+ });
|
|
|
} else {
|
|
|
var status = details && (cached_hash === new_hash) ? 3 : 2;
|
|
|
logging.debug(rid + "cached hash: " + (details && cached_hash));
|
|
@@ -261,7 +273,6 @@ exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|
|
// handles requests for +userId+ skins
|
|
|
// callback contains error, skin hash, image buffer
|
|
|
exp.get_skin = function(rid, userId, callback) {
|
|
|
- logging.log(rid + "skin request");
|
|
|
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
|
|
var skinpath = __dirname + "/../" + config.skins_dir + skin_hash + ".png";
|
|
|
fs.exists(skinpath, function(exists) {
|
|
@@ -312,7 +323,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
} else {
|
|
|
fs.writeFile(renderpath, img, "binary", function(err) {
|
|
|
if (err) {
|
|
|
- logging.log(rid + err.stack);
|
|
|
+ logging.error(rid + err.stack);
|
|
|
}
|
|
|
callback(null, 2, skin_hash, img);
|
|
|
});
|
|
@@ -326,7 +337,6 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|
|
// handles requests for +userId+ capes
|
|
|
// callback contains error, cape hash, image buffer
|
|
|
exp.get_cape = function(rid, userId, callback) {
|
|
|
- logging.log(rid + "cape request");
|
|
|
exp.get_image_hash(rid, userId, "cape", function(err, status, cape_hash) {
|
|
|
if (!cape_hash) {
|
|
|
callback(err, null, null);
|