mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
use array instead of object, use dashed names
This commit is contained in:
parent
8dddb1e022
commit
7a1ffc904b
@ -6,6 +6,7 @@ var fs = require("fs");
|
|||||||
var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
var skins_url = "https://skins.minecraft.net/MinecraftSkins/";
|
var skins_url = "https://skins.minecraft.net/MinecraftSkins/";
|
||||||
var capes_url = "https://skins.minecraft.net/MinecraftCloaks/";
|
var capes_url = "https://skins.minecraft.net/MinecraftCloaks/";
|
||||||
|
var mojang_urls = [skins_url, capes_url];
|
||||||
|
|
||||||
var exp = {};
|
var exp = {};
|
||||||
|
|
||||||
@ -81,17 +82,11 @@ exp.get_from = function(rid, url, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// specifies which numbers identify what url
|
|
||||||
var mojang_url_types = {
|
|
||||||
1: skins_url,
|
|
||||||
2: capes_url
|
|
||||||
};
|
|
||||||
|
|
||||||
// make a request to skins.miencraft.net
|
// make a request to skins.miencraft.net
|
||||||
// the skin url is taken from the HTTP redirect
|
// the skin url is taken from the HTTP redirect
|
||||||
// type reference is above
|
// type reference is above
|
||||||
exp.get_username_url = function(rid, name, type, callback) {
|
exp.get_username_url = function(rid, name, type, callback) {
|
||||||
exp.get_from(rid, mojang_url_types[type] + name + ".png", function(body, response, err) {
|
exp.get_from(rid, mojang_urls[type] + name + ".png", function(body, response, err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
callback(err, response ? (response.statusCode === 404 ? null : response.headers.location) : null);
|
callback(err, response ? (response.statusCode === 404 ? null : response.headers.location) : null);
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +123,7 @@ exp.get_profile = function(rid, uuid, callback) {
|
|||||||
// +uuid+ is used to get the url, otherwise
|
// +uuid+ is used to get the url, otherwise
|
||||||
// +profile+ will be used to get the url
|
// +profile+ will be used to get the url
|
||||||
exp.get_skin_url = function(rid, uuid, profile, callback) {
|
exp.get_skin_url = function(rid, uuid, profile, callback) {
|
||||||
getUrl(rid, uuid, profile, 1, function(url) {
|
get_url(rid, uuid, profile, 0, function(url) {
|
||||||
callback(url);
|
callback(url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -137,12 +132,12 @@ exp.get_skin_url = function(rid, uuid, profile, callback) {
|
|||||||
// +uuid+ is used to get the url, otherwise
|
// +uuid+ is used to get the url, otherwise
|
||||||
// +profile+ will be used to get the url
|
// +profile+ will be used to get the url
|
||||||
exp.get_cape_url = function(rid, uuid, profile, callback) {
|
exp.get_cape_url = function(rid, uuid, profile, callback) {
|
||||||
getUrl(rid, uuid, profile, 2, function(url) {
|
get_url(rid, uuid, profile, 1, function(url) {
|
||||||
callback(url);
|
callback(url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function getUrl(rid, uuid, profile, type, callback) {
|
function get_url(rid, uuid, profile, type, callback) {
|
||||||
if (uuid.length <= 16) {
|
if (uuid.length <= 16) {
|
||||||
//username
|
//username
|
||||||
exp.get_username_url(rid, uuid, type, function(err, url) {
|
exp.get_username_url(rid, uuid, type, function(err, url) {
|
||||||
|
|||||||
@ -94,7 +94,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not exist (username)", function(done) {
|
it("should not exist (username)", function(done) {
|
||||||
networking.get_username_url(rid, "Steve", 1, function(err, profile) {
|
networking.get_username_url(rid, "Steve", 0, function(err, profile) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -138,7 +138,7 @@ describe("Crafatar", function() {
|
|||||||
it("should time out on username info download", function(done) {
|
it("should time out on username info download", function(done) {
|
||||||
var original_timeout = config.http_timeout;
|
var original_timeout = config.http_timeout;
|
||||||
config.http_timeout = 1;
|
config.http_timeout = 1;
|
||||||
networking.get_username_url(rid, "redstone_sheep", 1, function(err, url) {
|
networking.get_username_url(rid, "redstone_sheep", 0, function(err, url) {
|
||||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
assert.strictEqual(err.code, "ETIMEDOUT");
|
||||||
config.http_timeout = original_timeout;
|
config.http_timeout = original_timeout;
|
||||||
done();
|
done();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user