crafatar/lib/routes/capes.js
jomo 13169be774 use new response module for capes + more
- made sure that get_cape returns a status
- response.js returns 404 if body is empty
- 'X-Storage-Type: undefined' is no longer returned when status is `null`
2015-04-21 23:27:10 +02:00

44 lines
930 B
JavaScript

var logging = require("../logging");
var helpers = require("../helpers");
var cache = require("../cache");
// GET cape request
module.exports = function(req, callback) {
var userId = (req.url.pathname.split("/")[2] || "").split(".")[0];
var rid = req.id;
if (!helpers.id_valid(userId)) {
callback({
status: -2,
body: "Invalid userid"
});
return;
}
// strip dashes
userId = userId.replace(/-/g, "");
try {
helpers.get_cape(rid, userId, function(err, hash, status, image) {
if (err) {
logging.error(rid, err);
if (err.code === "ENOENT") {
// no such file
cache.remove_hash(rid, userId);
}
}
callback({
status: status,
body: image,
type: image ? "image/png" : undefined,
hash: hash,
err: err
});
});
} catch(e) {
callback({
status: -1,
err: e
});
}
};