diff --git a/modules/helpers.js b/modules/helpers.js
index 8180e51..8c89be0 100644
--- a/modules/helpers.js
+++ b/modules/helpers.js
@@ -79,7 +79,7 @@ function skin_url(profile) {
// 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) {
@@ -96,7 +96,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);
}
});
}
diff --git a/routes/avatars.js b/routes/avatars.js
index af29152..9e91db1 100644
--- a/routes/avatars.js
+++ b/routes/avatars.js
@@ -3,6 +3,14 @@ var router = require('express').Router();
var config = require('../modules/config');
var skins = require('../modules/skins');
+var human_status = {
+ 0: "none",
+ 1: "cached",
+ 2: "checked",
+ 3: "downloaded",
+ "-1": "error"
+};
+
/* GET avatar request. */
router.get('/:uuid.:ext?', function(req, res) {
var uuid = req.params.uuid;
@@ -24,47 +32,37 @@ router.get('/:uuid.:ext?', function(req, res) {
try {
helpers.get_avatar(uuid, helm, size, function(err, status, image) {
- console.log(uuid + " - " + status);
+ console.log(uuid + " - " + human_status[status]);
if (err) {
console.error(err);
- if (image) {
- console.warn("error occured, image found anyway");
- sendimage(503, true, image);
- } else {
- handle_default(404);
- }
- } else if (status == 1 || status == 2) {
- sendimage(200, status == 1, image);
- } else if (status === 0 || status == 3) {
- handle_default(404);
+ }
+ if (image) {
+ sendimage(err ? 503 : 200, status, image);
} else {
- console.error("unexpected error/status");
- console.error("error: " + err);
- console.error("status: " + status);
- handle_default(404);
+ handle_default(404, status);
}
});
} catch(e) {
console.error("Error!");
console.error(e);
- handle_default(500);
+ handle_default(500, status);
}
- function handle_default(status) {
+ function handle_default(http_status, img_status) {
if (def != "steve" && def != "alex") {
def = skins.default_skin(uuid);
}
skins.resize_img("public/images/" + def + ".png", size, function(err, image) {
- sendimage(status, true, image);
+ sendimage(http_status, img_status, image);
});
}
- function sendimage(status, local, image) {
- res.writeHead(status, {
+ function sendimage(http_status, img_status, image) {
+ res.writeHead(http_status, {
'Content-Type': 'image/png',
'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
'Response-Time': new Date() - start,
- 'X-Storage-Type': local ? 'local' : 'downloaded'
+ 'X-Storage-Type': human_status[img_status]
});
res.end(image);
}
diff --git a/views/index.jade b/views/index.jade
index 17f3609..f26e0cd 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -38,7 +38,13 @@ block content
h4 Response-Time
p The time, in milliseconds, it took Crafatar to process the request.
h4 X-Storage-Type
- p Either 'local' or 'downloaded'. Local means that Crafatar already had the image on disk, while downloaded means that it was retrieved from Mojang's skin servers.
+ ul
+ li none: No external requests. Cached: User has no skin.
+ li cached: No external requests. Skin cached and stored locally.
+ li checked: 1 external request. Skin cached, checked for updates, no skin downloaded.
+ | This happens either when the user has no skin or it didn't change.
+ li downloaded: 2 external requests. Skin changed or unknown, downloaded.
+ li error: This can happen, for example, when Mojang's servers are down. If possible, an outdated image will be served instead.
h3 Examples
p Get jeb_'s avatar, 160 × 160 pixels