mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
always show image, get steve/alex by UUID, send correct HTTP status codes
This commit is contained in:
parent
9b3884d85a
commit
e592048ec1
@ -78,4 +78,13 @@ exp.resize_img = function(inname, size, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
// returns "alex" or "steve" calculated by the +uuid+
|
||||
exp.default_skin = function(uuid) {
|
||||
if (Number("0x" + uuid[31]) % 2 === 0) {
|
||||
return "alex";
|
||||
} else {
|
||||
return "steve";
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = exp;
|
||||
@ -29,35 +29,34 @@ router.get('/:uuid.:ext?', function(req, res) {
|
||||
console.error(err);
|
||||
if (image) {
|
||||
console.warn("error occured, image found anyway");
|
||||
sendimage(200, status, image);
|
||||
sendimage(503, true, image);
|
||||
} else {
|
||||
handle_404(def);
|
||||
handle_default(404);
|
||||
}
|
||||
} else if (status == 1 || status == 2) {
|
||||
sendimage(200, status == 1, image);
|
||||
} else if (status == 0 || status == 3) {
|
||||
handle_404(def);
|
||||
} else if (status === 0 || status == 3) {
|
||||
handle_default(404);
|
||||
} else {
|
||||
console.error("unexpected error/status");
|
||||
console.error("error: " + err);
|
||||
console.error("status: " + status);
|
||||
handle_404(def);
|
||||
handle_default(404);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
console.error("Error!");
|
||||
console.error(e);
|
||||
res.status(500).send("500 Internal server error");
|
||||
handle_default(500);
|
||||
}
|
||||
|
||||
function handle_404(def) {
|
||||
if (def == "alex" || def == "steve") {
|
||||
skins.resize_img("public/images/" + def + ".png", size, function(err, image) {
|
||||
sendimage(404, true, image);
|
||||
});
|
||||
} else {
|
||||
res.status(404).send('404 Not found');
|
||||
function handle_default(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);
|
||||
});
|
||||
}
|
||||
|
||||
function sendimage(status, local, image) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user