|
@@ -6,6 +6,7 @@ var fs = require("fs");
|
|
|
|
|
|
var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
|
|
var skins_url = "https://skins.minecraft.net/MinecraftSkins/";
|
|
|
+var capes_url = "https://skins.minecraft.net/MinecraftCloaks/";
|
|
|
|
|
|
// exracts the skin url of a +profile+ object
|
|
|
// returns null when no url found (user has no skin)
|
|
@@ -23,6 +24,20 @@ function extract_skin_url(profile) {
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
+function extract_cape_url(profile) {
|
|
|
+ var url = null;
|
|
|
+ if (profile && profile.properties) {
|
|
|
+ profile.properties.forEach(function(prop) {
|
|
|
+ if (prop.name == "textures") {
|
|
|
+ var json = Buffer(prop.value, "base64").toString();
|
|
|
+ var props = JSON.parse(json);
|
|
|
+ url = props && props.textures && props.textures.CAPE && props.textures.CAPE.url || null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return url;
|
|
|
+}
|
|
|
+
|
|
|
// make a request to skins.miencraft.net
|
|
|
// the skin url is taken from the HTTP redirect
|
|
|
var get_username_url = function(name, callback) {
|
|
@@ -104,6 +119,18 @@ exp.get_skin_url = function(uuid, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+exp.get_cape_url = function(uuid, callback) {
|
|
|
+ if (uuid.length <= 16) {
|
|
|
+ get_username_url(uuid, function(err, url) {
|
|
|
+ callback(err, url);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ get_uuid_url(uuid, function(err, url) {
|
|
|
+ callback(err, url);
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
// downloads skin file from +url+
|
|
|
// callback contains error, image
|
|
|
exp.get_skin = function(url, uuid, callback) {
|
|
@@ -162,4 +189,37 @@ exp.save_skin = function(uuid, hash, outpath, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-module.exports = exp;
|
|
|
+exp.get_cape = function(url, callback) {
|
|
|
+ request.get({
|
|
|
+ url: url,
|
|
|
+ headers: {
|
|
|
+ "User-Agent": "https://crafatar.com"
|
|
|
+ },
|
|
|
+ encoding: null, // encoding must be null so we get a buffer
|
|
|
+ timeout: config.http_timeout // ms
|
|
|
+ }, function (error, response, body) {
|
|
|
+ if (!error && response.statusCode == 200) {
|
|
|
+ // cape downloaded successfully
|
|
|
+ logging.log("downloaded cape");
|
|
|
+ logging.debug(url);
|
|
|
+ callback(null, body);
|
|
|
+ } else {
|
|
|
+ if (error) {
|
|
|
+ logging.error("Error downloading '" + url + "': " + error);
|
|
|
+ } else if (response.statusCode == 404) {
|
|
|
+ logging.warn("texture not found (404): " + url);
|
|
|
+ } else if (response.statusCode == 429) {
|
|
|
+ logging.warn("too many requests for " + url);
|
|
|
+ logging.warn(body);
|
|
|
+ } else {
|
|
|
+ logging.error("unknown error for " + url);
|
|
|
+ logging.error(response);
|
|
|
+ logging.error(body);
|
|
|
+ error = "unknown error"; // Error needs to be set, otherwise null in callback
|
|
|
+ }
|
|
|
+ callback(error, null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = exp;
|