mirror of
https://github.com/azures04/crafatar.git
synced 2026-05-06 19:10:38 +02:00
❤️ eslint
This commit is contained in:
@@ -22,6 +22,20 @@ module.exports = function(req, res) {
|
||||
var etag = null;
|
||||
var rid = req.id;
|
||||
|
||||
function sendimage(rid, http_status, img_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
|
||||
// Prevent app from crashing/freezing
|
||||
if (size < config.min_size || size > config.max_size) {
|
||||
// "Unprocessable Entity", valid request, but semantically erroneous:
|
||||
@@ -96,18 +110,4 @@ module.exports = function(req, res) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sendimage(rid, http_status, img_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -18,6 +18,19 @@ module.exports = function(req, res) {
|
||||
var etag = null;
|
||||
var rid = req.id;
|
||||
|
||||
function sendimage(rid, 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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
|
||||
if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
@@ -70,17 +83,4 @@ module.exports = function(req, res) {
|
||||
});
|
||||
res.end("500 server error");
|
||||
}
|
||||
|
||||
function sendimage(rid, 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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,8 +1,9 @@
|
||||
var config = require("../lib/config");
|
||||
var path = require("path");
|
||||
var jade = require("jade");
|
||||
|
||||
// compile jade
|
||||
var index = jade.compileFile(__dirname + "/../views/index.jade");
|
||||
var index = jade.compileFile(path.join(__dirname, "../views/index.jade"));
|
||||
|
||||
module.exports = function(req, res) {
|
||||
var html = index({
|
||||
|
||||
@@ -41,6 +41,52 @@ module.exports = function(req, res) {
|
||||
var helm = req.url.query.hasOwnProperty("helm");
|
||||
var etag = null;
|
||||
|
||||
function sendimage(rid, http_status, img_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
|
||||
// default alex/steve images can be rendered, but
|
||||
// custom images will not be
|
||||
function handle_default(rid, http_status, img_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid, "status: 301");
|
||||
res.writeHead(301, {
|
||||
"Cache-Control": "max-age=" + config.browser_cache_time + ", public",
|
||||
"Response-Time": new Date() - start,
|
||||
"X-Storage-Type": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Location": def
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
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
|
||||
logging.error(rid, "error loading default render image:", err);
|
||||
}
|
||||
// we render the default skins, but not custom images
|
||||
renders.draw_model(rid, buf, scale, helm, body, function(render_err, def_img) {
|
||||
if (render_err) {
|
||||
logging.error(rid, "error while rendering default image:", render_err);
|
||||
}
|
||||
sendimage(rid, http_status, img_status, def_img);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (scale < config.min_scale || scale > config.max_scale) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
@@ -92,51 +138,4 @@ module.exports = function(req, res) {
|
||||
logging.error(rid, "error:", e.stack);
|
||||
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, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid, "status: 301");
|
||||
res.writeHead(301, {
|
||||
"Cache-Control": "max-age=" + config.browser_cache_time + ", public",
|
||||
"Response-Time": new Date() - start,
|
||||
"X-Storage-Type": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Location": def
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
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
|
||||
logging.error(rid, "error loading default render image:", err);
|
||||
}
|
||||
// we render the default skins, but not custom images
|
||||
renders.draw_model(rid, buf, scale, helm, body, function(err, def_img) {
|
||||
if (err) {
|
||||
logging.error(rid, "error while rendering default image:", err);
|
||||
}
|
||||
sendimage(rid, http_status, img_status, def_img);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sendimage(rid, http_status, img_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": human_status[img_status],
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
};
|
||||
@@ -12,6 +12,44 @@ module.exports = function(req, res) {
|
||||
var etag = null;
|
||||
var rid = req.id;
|
||||
|
||||
function sendimage(rid, http_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": "downloaded",
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
|
||||
function handle_default(rid, http_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid, "status: 301");
|
||||
res.writeHead(301, {
|
||||
"Cache-Control": "max-age=" + config.browser_cache_time + ", public",
|
||||
"Response-Time": new Date() - start,
|
||||
"X-Storage-Type": "downloaded",
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Location": def
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
def = def || skins.default_skin(userId);
|
||||
lwip.open("public/images/" + def + "_skin.png", function(err, image) {
|
||||
// FIXME: err is not handled
|
||||
image.toBuffer("png", function(buf_err, buffer) {
|
||||
// FIXME: buf_err is not handled
|
||||
sendimage(rid, http_status, buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!helpers.id_valid(userId)) {
|
||||
res.writeHead(422, {
|
||||
"Content-Type": "text/plain",
|
||||
@@ -50,40 +88,4 @@ module.exports = function(req, res) {
|
||||
logging.error(rid, "error:", e.stack);
|
||||
handle_default(rid, 500, userId);
|
||||
}
|
||||
|
||||
function handle_default(rid, http_status, userId) {
|
||||
if (def && def !== "steve" && def !== "alex") {
|
||||
logging.log(rid, "status: 301");
|
||||
res.writeHead(301, {
|
||||
"Cache-Control": "max-age=" + config.browser_cache_time + ", public",
|
||||
"Response-Time": new Date() - start,
|
||||
"X-Storage-Type": "downloaded",
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Location": def
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sendimage(rid, http_status, image) {
|
||||
logging.log(rid, "status:", http_status);
|
||||
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": "downloaded",
|
||||
"X-Request-ID": rid,
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Etag": '"' + etag + '"'
|
||||
});
|
||||
res.end(http_status === 304 ? null : image);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user