mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
remove expressjs from avatars
This commit is contained in:
parent
3ac98c88cf
commit
958b1ea907
@ -1,4 +1,3 @@
|
|||||||
var router = require("express").Router();
|
|
||||||
var networking = require("../modules/networking");
|
var networking = require("../modules/networking");
|
||||||
var logging = require("../modules/logging");
|
var logging = require("../modules/logging");
|
||||||
var helpers = require("../modules/helpers");
|
var helpers = require("../modules/helpers");
|
||||||
@ -13,12 +12,13 @@ var human_status = {
|
|||||||
"-1": "error"
|
"-1": "error"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* GET avatar request. */
|
// GET avatar request
|
||||||
router.get("/:uuid.:ext?", function(req, res) {
|
module.exports = function(req, res) {
|
||||||
var uuid = (req.params.uuid || "");
|
logging.debug(req.url.pathname);
|
||||||
var size = parseInt(req.query.size) || config.default_size;
|
var uuid = (req.url.pathname.split("/")[2] || "");
|
||||||
var def = req.query.default;
|
var size = parseInt(req.url.query.size) || config.default_size;
|
||||||
var helm = req.query.hasOwnProperty("helm");
|
var def = req.url.query.default;
|
||||||
|
var helm = req.url.query.hasOwnProperty("helm");
|
||||||
var start = new Date();
|
var start = new Date();
|
||||||
var etag = null;
|
var etag = null;
|
||||||
|
|
||||||
@ -26,10 +26,12 @@ router.get("/:uuid.:ext?", function(req, res) {
|
|||||||
if (size < config.min_size || size > config.max_size) {
|
if (size < config.min_size || size > config.max_size) {
|
||||||
// "Unprocessable Entity", valid request, but semantically erroneous:
|
// "Unprocessable Entity", valid request, but semantically erroneous:
|
||||||
// https://tools.ietf.org/html/rfc4918#page-78
|
// https://tools.ietf.org/html/rfc4918#page-78
|
||||||
res.status(422).send("422 Invalid size");
|
res.writeHead(422);
|
||||||
|
res.end("Invalid size");
|
||||||
return;
|
return;
|
||||||
} else if (!helpers.uuid_valid(uuid)) {
|
} else if (!helpers.uuid_valid(uuid)) {
|
||||||
res.status(422).send("422 Invalid UUID");
|
res.writeHead(422);
|
||||||
|
res.end("Invalid UUID");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ router.get("/:uuid.:ext?", function(req, res) {
|
|||||||
logging.error(uuid + " " + err);
|
logging.error(uuid + " " + err);
|
||||||
}
|
}
|
||||||
etag = hash && hash.substr(0, 32) || "none";
|
etag = hash && hash.substr(0, 32) || "none";
|
||||||
var matches = req.get("If-None-Match") == '"' + etag + '"';
|
var matches = req.headers["if-none-match"] == '"' + etag + '"';
|
||||||
if (image) {
|
if (image) {
|
||||||
var http_status = 200;
|
var http_status = 200;
|
||||||
if (matches) {
|
if (matches) {
|
||||||
@ -51,7 +53,7 @@ router.get("/:uuid.:ext?", function(req, res) {
|
|||||||
} else if (err) {
|
} else if (err) {
|
||||||
http_status = 503;
|
http_status = 503;
|
||||||
}
|
}
|
||||||
logging.debug("Etag: " + req.get("If-None-Match"));
|
logging.debug("Etag: " + req.headers["if-none-match"]);
|
||||||
logging.debug("matches: " + matches);
|
logging.debug("matches: " + matches);
|
||||||
logging.log("status: " + http_status);
|
logging.log("status: " + http_status);
|
||||||
sendimage(http_status, status, image);
|
sendimage(http_status, status, image);
|
||||||
@ -94,7 +96,4 @@ router.get("/:uuid.:ext?", function(req, res) {
|
|||||||
});
|
});
|
||||||
res.end(http_status == 304 ? null : image);
|
res.end(http_status == 304 ? null : image);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
31
server.js
31
server.js
@ -15,7 +15,7 @@ var routes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function asset_request(req, res) {
|
function asset_request(req, res) {
|
||||||
var filename = __dirname + "/public/" + req.pathname;
|
var filename = __dirname + "/public/" + req.url.pathname;
|
||||||
fs.exists(filename, function(exists) {
|
fs.exists(filename, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
fs.readFile(filename, function(err, contents) {
|
fs.readFile(filename, function(err, contents) {
|
||||||
@ -41,27 +41,30 @@ function asset_request(req, res) {
|
|||||||
|
|
||||||
function requestHandler(req, res) {
|
function requestHandler(req, res) {
|
||||||
var querystring = url.parse(req.url).query;
|
var querystring = url.parse(req.url).query;
|
||||||
|
var request = req;
|
||||||
// we need to use url.parse and give the result to url.parse because nodejs
|
// we need to use url.parse and give the result to url.parse because nodejs
|
||||||
var prequest = url.parse(req.url, querystring);
|
request.url = url.parse(req.url, querystring);
|
||||||
|
request.url.query = request.url.query || {};
|
||||||
|
|
||||||
console.log("Request: " + prequest.pathname);
|
var local_path = request.url.pathname.split("/")[1];
|
||||||
console.log("Params: " + JSON.stringify(prequest.query));
|
console.log("Request: " + request.url.pathname + " (" + local_path + ")");
|
||||||
|
console.log(request.headers);
|
||||||
|
|
||||||
switch (prequest.pathname) {
|
switch (local_path) {
|
||||||
case "/":
|
case "":
|
||||||
routes.index(prequest, res);
|
routes.index(request, res);
|
||||||
break;
|
break;
|
||||||
case "/avatars":
|
case "avatars":
|
||||||
routes.avatars(prequest, res);
|
routes.avatars(request, res);
|
||||||
break;
|
break;
|
||||||
case "/skins":
|
case "skins":
|
||||||
routes.skins(prequest, res);
|
routes.skins(request, res);
|
||||||
break;
|
break;
|
||||||
case "/renders":
|
case "renders":
|
||||||
routes.renders(prequest, res);
|
routes.renders(request, res);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
asset_request(prequest, res);
|
asset_request(request, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user