From 703b8e6a8a2c202fc4adde69b94a73fbf5b93afd Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 29 Nov 2014 14:48:59 -0600 Subject: [PATCH 1/3] Use node instead of npm to start --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 7778d31..10e2b3b 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: cp "modules/config.example.js" "modules/config.js" && npm start \ No newline at end of file +web: cp "modules/config.example.js" "modules/config.js" && node server.js \ No newline at end of file From 6eef94d6f54f1f5fa74a0b0e2e4e27b6637d87fa Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 29 Nov 2014 14:52:29 -0600 Subject: [PATCH 2/3] Oops..... :poop: --- routes/skins.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 routes/skins.js diff --git a/routes/skins.js b/routes/skins.js new file mode 100644 index 0000000..6bf3705 --- /dev/null +++ b/routes/skins.js @@ -0,0 +1,84 @@ +var router = require('express').Router(); +var networking = require('../modules/networking'); +var logging = require('../modules/logging'); +var helpers = require('../modules/helpers'); +var config = require('../modules/config'); +var skins = require('../modules/skins'); + +/* GET skin request. */ +router.get('/:uuid.:ext?', function(req, res) { + var uuid = req.params.uuid; + var def = req.query.default; + var start = new Date(); + var etag = null; + + if (!helpers.uuid_valid(uuid)) { + res.status(422).send("422 Invalid UUID"); + return; + } + + // strip dashes + uuid = uuid.replace(/-/g, ""); + + try { + helpers.get_skin(uuid, function(err, hash, image) { + logging.log(uuid); + if (err) { + logging.error(err); + } + etag = hash && hash.substr(0, 32) || "none"; + var matches = req.get("If-None-Match") == '"' + etag + '"'; + if (image) { + var http_status = 200; + if (matches) { + http_status = 304; + } else if (err) { + http_status = 503; + } + logging.log("matches: " + matches); + logging.log("Etag: " + req.get("If-None-Match")); + logging.log("status: " + http_status); + sendimage(http_status, image); + } else { + handle_default(404); + } + }); + } catch(e) { + logging.error("Error!"); + logging.error(e); + handle_default(500); + } + + function handle_default(http_status) { + if (def && def != "steve" && def != "alex") { + res.writeHead(301, { + 'Cache-Control': 'max-age=' + config.browser_cache_time + ', public', + 'Response-Time': new Date() - start, + 'X-Storage-Type': "downloaded", + 'Access-Control-Allow-Origin': '*', + 'Location': def + }); + res.end(); + } else { + def = def || skins.default_skin(uuid); + skins.resize_img("public/images/" + def + ".png", size, function(err, image) { + sendimage(http_status, image); + }); + } + } + + function sendimage(http_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': "downloaded", + 'Access-Control-Allow-Origin': '*', + 'Etag': '"' + etag + '"' + }); + res.end(http_status == 304 ? null : image); + } +}); + + +module.exports = router; \ No newline at end of file From df592034f632cb012b5f3226e5f9e09e99dc6b63 Mon Sep 17 00:00:00 2001 From: Jake Date: Sat, 29 Nov 2014 15:35:14 -0600 Subject: [PATCH 3/3] Fix callback --- modules/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/helpers.js b/modules/helpers.js index a2599bd..55e7280 100644 --- a/modules/helpers.js +++ b/modules/helpers.js @@ -149,7 +149,7 @@ exp.get_skin = function(uuid, callback) { exp.get_image_hash(uuid, function(err, status, hash) { if (hash) { var skinurl = "http://textures.minecraft.net/texture/" + hash; - networking.get_skin(skinurl, null, function(err, img) { + networking.get_skin(skinurl, function(err, img) { if (err) { logging.log("\nerror while downloading skin"); callback(err, hash, null);