mirror of
https://github.com/azures04/crafatar.git
synced 2026-05-06 11:00:39 +02:00
uuid -> userId closes #62
This commit is contained in:
@@ -15,7 +15,7 @@ var human_status = {
|
||||
// GET avatar request
|
||||
module.exports = function(req, res) {
|
||||
var start = new Date();
|
||||
var uuid = (req.url.path_list[2] || "").split(".")[0];
|
||||
var userId = (req.url.path_list[2] || "").split(".")[0];
|
||||
var size = parseInt(req.url.query.size) || config.default_size;
|
||||
var def = req.url.query.default;
|
||||
var helm = req.url.query.hasOwnProperty("helm");
|
||||
@@ -32,27 +32,27 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end("Invalid Size");
|
||||
return;
|
||||
} else if (!helpers.uuid_valid(uuid)) {
|
||||
} else if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
"Response-Time": new Date() - start
|
||||
});
|
||||
res.end("Invalid UUID");
|
||||
res.end("Invalid ID");
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
uuid = uuid.replace(/-/g, "");
|
||||
logging.log(rid + "uuid: " + uuid);
|
||||
userId = userId.replace(/-/g, "");
|
||||
logging.log(rid + "userid: " + userId);
|
||||
|
||||
try {
|
||||
helpers.get_avatar(rid, uuid, helm, size, function(err, status, image, hash) {
|
||||
helpers.get_avatar(rid, userId, helm, size, function(err, status, image, hash) {
|
||||
logging.log(rid + "storage type: " + human_status[status]);
|
||||
if (err) {
|
||||
logging.error(rid + err);
|
||||
if (err.code === "ENOENT") {
|
||||
// no such file
|
||||
cache.remove_hash(rid, uuid);
|
||||
cache.remove_hash(rid, userId);
|
||||
}
|
||||
}
|
||||
etag = image && hash && hash.substr(0, 32) || "none";
|
||||
@@ -68,15 +68,15 @@ module.exports = function(req, res) {
|
||||
logging.debug(rid + "matches: " + matches);
|
||||
sendimage(rid, http_status, status, image);
|
||||
} else {
|
||||
handle_default(rid, 404, status, uuid);
|
||||
handle_default(rid, 404, status, userId);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
logging.error(rid + "error: " + e.stack);
|
||||
handle_default(rid, 500, -1, uuid);
|
||||
handle_default(rid, 500, -1, userId);
|
||||
}
|
||||
|
||||
function handle_default(rid, http_status, img_status, uuid) {
|
||||
function handle_default(rid, http_status, img_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid + "status: 301");
|
||||
res.writeHead(301, {
|
||||
@@ -89,7 +89,7 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
def = def || skins.default_skin(uuid);
|
||||
def = def || skins.default_skin(userId);
|
||||
skins.resize_img("public/images/" + def + ".png", size, function(err, image) {
|
||||
sendimage(rid, http_status, img_status, image);
|
||||
});
|
||||
|
||||
@@ -13,11 +13,11 @@ var human_status = {
|
||||
// GET cape request
|
||||
module.exports = function(req, res) {
|
||||
var start = new Date();
|
||||
var uuid = (req.url.pathname.split("/")[2] || "").split(".")[0];
|
||||
var userId = (req.url.pathname.split("/")[2] || "").split(".")[0];
|
||||
var etag = null;
|
||||
var rid = req.id;
|
||||
|
||||
if (!helpers.uuid_valid(uuid)) {
|
||||
if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
"Response-Time": new Date() - start
|
||||
@@ -27,17 +27,17 @@ module.exports = function(req, res) {
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
uuid = uuid.replace(/-/g, "");
|
||||
logging.log(rid + "uuid: " + uuid);
|
||||
userId = userId.replace(/-/g, "");
|
||||
logging.log(rid + "userid: " + userId);
|
||||
|
||||
try {
|
||||
helpers.get_cape(rid, uuid, function(err, status, image, hash) {
|
||||
helpers.get_cape(rid, userId, function(err, status, image, hash) {
|
||||
logging.log(rid + "storage type: " + human_status[status]);
|
||||
if (err) {
|
||||
logging.error(rid + err);
|
||||
if (err.code == "ENOENT") {
|
||||
// no such file
|
||||
cache.remove_hash(rid, uuid);
|
||||
cache.remove_hash(rid, userId);
|
||||
}
|
||||
}
|
||||
etag = hash && hash.substr(0, 32) || "none";
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = function(req, res) {
|
||||
}
|
||||
|
||||
var body = raw_type === "body";
|
||||
var uuid = (req.url.path_list[3] || "").split(".")[0];
|
||||
var userId = (req.url.path_list[3] || "").split(".")[0];
|
||||
var def = req.url.query.default;
|
||||
var scale = parseInt(req.url.query.scale) || config.default_scale;
|
||||
var helm = req.url.query.hasOwnProperty("helm");
|
||||
@@ -47,27 +47,27 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end("422 Invalid Scale");
|
||||
return;
|
||||
} else if (!helpers.uuid_valid(uuid)) {
|
||||
} else if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
"Response-Time": new Date() - start
|
||||
});
|
||||
res.end("422 Invalid UUID");
|
||||
res.end("422 Invalid ID");
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
uuid = uuid.replace(/-/g, "");
|
||||
logging.log(rid + "uuid: " + uuid);
|
||||
userId = userId.replace(/-/g, "");
|
||||
logging.log(rid + "userId: " + userId);
|
||||
|
||||
try {
|
||||
helpers.get_render(rid, uuid, scale, helm, body, function(err, status, hash, image) {
|
||||
helpers.get_render(rid, userId, scale, helm, body, function(err, status, hash, image) {
|
||||
logging.log(rid + "storage type: " + human_status[status]);
|
||||
if (err) {
|
||||
logging.error(rid + err);
|
||||
if (err.code == "ENOENT") {
|
||||
// no such file
|
||||
cache.remove_hash(rid, uuid);
|
||||
cache.remove_hash(rid, userId);
|
||||
}
|
||||
}
|
||||
etag = hash && hash.substr(0, 32) || "none";
|
||||
@@ -84,18 +84,18 @@ module.exports = function(req, res) {
|
||||
sendimage(rid, http_status, status, image);
|
||||
} else {
|
||||
logging.log(rid + "image not found, using default.");
|
||||
handle_default(rid, 404, status, uuid);
|
||||
handle_default(rid, 404, status, userId);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
logging.error(rid + "error: " + e.stack);
|
||||
handle_default(rid, 500, -1, uuid);
|
||||
handle_default(rid, 500, -1, userId);
|
||||
}
|
||||
|
||||
|
||||
// default alex/steve images can be rendered, but
|
||||
// custom images will not be
|
||||
function handle_default(rid, http_status, img_status, uuid) {
|
||||
function handle_default(rid, http_status, img_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid + "status: 301");
|
||||
res.writeHead(301, {
|
||||
@@ -108,7 +108,7 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
def = def || skins.default_skin(uuid);
|
||||
def = def || skins.default_skin(userId);
|
||||
fs.readFile("public/images/" + def + "_skin.png", function (err, buf) {
|
||||
if (err) {
|
||||
// errored while loading the default image, continuing with null image
|
||||
|
||||
@@ -7,26 +7,26 @@ var lwip = require("lwip");
|
||||
// GET skin request
|
||||
module.exports = function(req, res) {
|
||||
var start = new Date();
|
||||
var uuid = (req.url.path_list[2] || "").split(".")[0];
|
||||
var userId = (req.url.path_list[2] || "").split(".")[0];
|
||||
var def = req.url.query.default;
|
||||
var etag = null;
|
||||
var rid = req.id;
|
||||
|
||||
if (!helpers.uuid_valid(uuid)) {
|
||||
if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
"Response-Time": new Date() - start
|
||||
});
|
||||
res.end("Invalid UUID");
|
||||
res.end("Invalid ID");
|
||||
return;
|
||||
}
|
||||
|
||||
// strip dashes
|
||||
uuid = uuid.replace(/-/g, "");
|
||||
logging.log(rid + "uuid: " + uuid);
|
||||
userId = userId.replace(/-/g, "");
|
||||
logging.log(rid + "userid: " + userId);
|
||||
|
||||
try {
|
||||
helpers.get_skin(rid, uuid, function(err, hash, image) {
|
||||
helpers.get_skin(rid, userId, function(err, hash, image) {
|
||||
if (err) {
|
||||
logging.error(rid + err);
|
||||
}
|
||||
@@ -43,15 +43,15 @@ module.exports = function(req, res) {
|
||||
logging.debug(rid + "matches: " + matches);
|
||||
sendimage(rid, http_status, image);
|
||||
} else {
|
||||
handle_default(rid, 404, uuid);
|
||||
handle_default(rid, 404, userId);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
logging.error(rid + "error: " + e.stack);
|
||||
handle_default(rid, 500, uuid);
|
||||
handle_default(rid, 500, userId);
|
||||
}
|
||||
|
||||
function handle_default(rid, http_status, uuid) {
|
||||
function handle_default(rid, http_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid + "status: 301");
|
||||
res.writeHead(301, {
|
||||
@@ -64,7 +64,7 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
def = def || skins.default_skin(uuid);
|
||||
def = def || skins.default_skin(userId);
|
||||
lwip.open("public/images/" + def + "_skin.png", function(err, image) {
|
||||
image.toBuffer("png", function(err, buffer) {
|
||||
sendimage(rid, http_status, buffer);
|
||||
|
||||
Reference in New Issue
Block a user