mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
better X-Storage-Type
none: Cached: User has no skin. cached: Skin cached checked: cached & checked for updates. No (new) skin downloaded: checked, Skin changed or unknown, downloaded. error: (error)
This commit is contained in:
parent
66914efb19
commit
03306dff08
@ -79,7 +79,7 @@ function skin_url(profile) {
|
|||||||
// 0: cached as null
|
// 0: cached as null
|
||||||
// 1: found on disk
|
// 1: found on disk
|
||||||
// 2: profile requested/found, skin downloaded from mojang servers
|
// 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) {
|
function get_image_hash(uuid, callback) {
|
||||||
cache.get_details(uuid, function(err, details) {
|
cache.get_details(uuid, function(err, details) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -96,7 +96,7 @@ function get_image_hash(uuid, callback) {
|
|||||||
callback(err, -1, details && details.hash);
|
callback(err, -1, details && details.hash);
|
||||||
} else {
|
} else {
|
||||||
console.log(uuid + " hash: " + hash);
|
console.log(uuid + " hash: " + hash);
|
||||||
callback(null, (hash ? 2 : 3), hash);
|
callback(null, (hash != (details && details.hash) ? 2 : 3), hash);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,14 @@ var router = require('express').Router();
|
|||||||
var config = require('../modules/config');
|
var config = require('../modules/config');
|
||||||
var skins = require('../modules/skins');
|
var skins = require('../modules/skins');
|
||||||
|
|
||||||
|
var human_status = {
|
||||||
|
0: "none",
|
||||||
|
1: "cached",
|
||||||
|
2: "checked",
|
||||||
|
3: "downloaded",
|
||||||
|
"-1": "error"
|
||||||
|
};
|
||||||
|
|
||||||
/* GET avatar request. */
|
/* GET avatar request. */
|
||||||
router.get('/:uuid.:ext?', function(req, res) {
|
router.get('/:uuid.:ext?', function(req, res) {
|
||||||
var uuid = req.params.uuid;
|
var uuid = req.params.uuid;
|
||||||
@ -24,47 +32,37 @@ router.get('/:uuid.:ext?', function(req, res) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
helpers.get_avatar(uuid, helm, size, function(err, status, image) {
|
helpers.get_avatar(uuid, helm, size, function(err, status, image) {
|
||||||
console.log(uuid + " - " + status);
|
console.log(uuid + " - " + human_status[status]);
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(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) {
|
if (image) {
|
||||||
sendimage(200, status == 1, image);
|
sendimage(err ? 503 : 200, status, image);
|
||||||
} else if (status === 0 || status == 3) {
|
|
||||||
handle_default(404);
|
|
||||||
} else {
|
} else {
|
||||||
console.error("unexpected error/status");
|
handle_default(404, status);
|
||||||
console.error("error: " + err);
|
|
||||||
console.error("status: " + status);
|
|
||||||
handle_default(404);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("Error!");
|
console.error("Error!");
|
||||||
console.error(e);
|
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") {
|
if (def != "steve" && def != "alex") {
|
||||||
def = skins.default_skin(uuid);
|
def = skins.default_skin(uuid);
|
||||||
}
|
}
|
||||||
skins.resize_img("public/images/" + def + ".png", size, function(err, image) {
|
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) {
|
function sendimage(http_status, img_status, image) {
|
||||||
res.writeHead(status, {
|
res.writeHead(http_status, {
|
||||||
'Content-Type': 'image/png',
|
'Content-Type': 'image/png',
|
||||||
'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
|
'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
|
||||||
'Response-Time': new Date() - start,
|
'Response-Time': new Date() - start,
|
||||||
'X-Storage-Type': local ? 'local' : 'downloaded'
|
'X-Storage-Type': human_status[img_status]
|
||||||
});
|
});
|
||||||
res.end(image);
|
res.end(image);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,13 @@ block content
|
|||||||
h4 Response-Time
|
h4 Response-Time
|
||||||
p The time, in milliseconds, it took Crafatar to process the request.
|
p The time, in milliseconds, it took Crafatar to process the request.
|
||||||
h4 X-Storage-Type
|
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 <b>none</b>: No external requests. Cached: User has no skin.
|
||||||
|
li <b>cached</b>: No external requests. Skin cached and stored locally.
|
||||||
|
li <b>checked</b>: 1 external request. Skin cached, checked for updates, no skin downloaded.<br>
|
||||||
|
| This happens either when the user has no skin or it didn't change.
|
||||||
|
li <b>downloaded</b>: 2 external requests. Skin changed or unknown, downloaded.
|
||||||
|
li <b>error</b>: This can happen, for example, when Mojang's servers are down. If possible, an outdated image will be served instead.
|
||||||
|
|
||||||
h3 Examples
|
h3 Examples
|
||||||
p Get jeb_'s avatar, 160 × 160 pixels
|
p Get jeb_'s avatar, 160 × 160 pixels
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user