mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
heyo!
This commit is contained in:
parent
5a258bb651
commit
9fa9342bdc
@ -172,7 +172,8 @@ exp.get_image_hash = function(uuid, raw_type, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
callback(err, -1, null);
|
callback(err, -1, null);
|
||||||
} else {
|
} else {
|
||||||
if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {logging.log(uuid + " uuid cached & recently updated");
|
if (details && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
||||||
|
logging.log(uuid + " uuid cached & recently updated");
|
||||||
callback(null, (type ? 1 : 0), type);
|
callback(null, (type ? 1 : 0), type);
|
||||||
} else {
|
} else {
|
||||||
if (details) {
|
if (details) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var logging = require("./logging");
|
var logging = require("./logging");
|
||||||
var request = require("requestretry");
|
var request = require("request");
|
||||||
var config = require("./config");
|
var config = require("./config");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
@ -41,7 +41,8 @@ exp.extract_cape_url = function(profile) {
|
|||||||
// specified. +callback+ contains the body, response,
|
// specified. +callback+ contains the body, response,
|
||||||
// and error buffer. get_from helper method is available
|
// and error buffer. get_from helper method is available
|
||||||
exp.get_from_options = function(url, options, callback) {
|
exp.get_from_options = function(url, options, callback) {
|
||||||
request({
|
console.log("HERE: " + config.http_timeout)
|
||||||
|
request.get({
|
||||||
url: url,
|
url: url,
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "https://crafatar.com"
|
"User-Agent": "https://crafatar.com"
|
||||||
@ -49,9 +50,7 @@ exp.get_from_options = function(url, options, callback) {
|
|||||||
timeout: (options.timeout || config.http_timeout),
|
timeout: (options.timeout || config.http_timeout),
|
||||||
encoding: (options.encoding || null),
|
encoding: (options.encoding || null),
|
||||||
followRedirect: (options.folow_redirect || false),
|
followRedirect: (options.folow_redirect || false),
|
||||||
maxAttempts: 2,
|
maxAttempts: (options.max_attempts || 2)
|
||||||
retryDelay: 2000,
|
|
||||||
retryStrategy: request.RetryStrategies.NetworkError
|
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
// 200 or 301 depending on content type
|
// 200 or 301 depending on content type
|
||||||
if (!error && (response.statusCode === 200 || response.statusCode === 301)) {
|
if (!error && (response.statusCode === 200 || response.statusCode === 301)) {
|
||||||
@ -61,7 +60,7 @@ exp.get_from_options = function(url, options, callback) {
|
|||||||
} else if (error) {
|
} else if (error) {
|
||||||
callback(body || null, response, error);
|
callback(body || null, response, error);
|
||||||
} else if (response.statusCode === 404) {
|
} else if (response.statusCode === 404) {
|
||||||
// page doesn't exist
|
// page does not exist
|
||||||
logging.log(url + " url does not exist");
|
logging.log(url + " url does not exist");
|
||||||
callback(null, response, null);
|
callback(null, response, null);
|
||||||
} else if (response.statusCode === 429) {
|
} else if (response.statusCode === 429) {
|
||||||
@ -121,13 +120,11 @@ exp.get_profile = function(uuid, callback) {
|
|||||||
callback(null, null);
|
callback(null, null);
|
||||||
} else {
|
} else {
|
||||||
exp.get_from_options(session_url + uuid, { encoding: "utf8" }, function(body, response, err) {
|
exp.get_from_options(session_url + uuid, { encoding: "utf8" }, function(body, response, err) {
|
||||||
callback(err !== null ? err : null, (body !== null ? JSON.parse(body) : null));
|
callback(err || null, (body !== null ? JSON.parse(body) : null));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo remove middleman
|
|
||||||
|
|
||||||
// +uuid+ is likely a username and if so
|
// +uuid+ is likely a username and if so
|
||||||
// +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
|
||||||
@ -161,7 +158,7 @@ function getUrl(uuid, profile, type, callback) {
|
|||||||
|
|
||||||
// downloads skin file from +url+
|
// downloads skin file from +url+
|
||||||
// callback contains error, image
|
// callback contains error, image
|
||||||
exp.get_skin = function(url, callback) {
|
exp.get_skin = function(url, uuid, callback) {
|
||||||
exp.get_from(url, function(body, response, err) {
|
exp.get_from(url, function(body, response, err) {
|
||||||
callback(body, err);
|
callback(body, err);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
"jade": "~1.8.2",
|
"jade": "~1.8.2",
|
||||||
"lwip": "0.0.6",
|
"lwip": "0.0.6",
|
||||||
"redis": "0.12.1",
|
"redis": "0.12.1",
|
||||||
"requestretry": "1.2.2",
|
"request": "2.51.1",
|
||||||
"node-df": "0.1.1",
|
"node-df": "0.1.1",
|
||||||
"mime": "1.2.11"
|
"mime": "1.2.11"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -29,8 +29,8 @@ function getRandomInt(min, max) {
|
|||||||
|
|
||||||
var ids = [
|
var ids = [
|
||||||
uuid.toLowerCase(),
|
uuid.toLowerCase(),
|
||||||
uuid.toUpperCase(),
|
|
||||||
name.toLowerCase(),
|
name.toLowerCase(),
|
||||||
|
uuid.toUpperCase(),
|
||||||
name.toUpperCase()
|
name.toUpperCase()
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -145,8 +145,8 @@ describe("Crafatar", function() {
|
|||||||
it("should time out on skin download", function(done) {
|
it("should time out on skin 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_skin("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", uuid, function(err, img) {
|
networking.get_from("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(body, res, error) {
|
||||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
assert.strictEqual(error.code, "ETIMEDOUT");
|
||||||
config.http_timeout = original_timeout;
|
config.http_timeout = original_timeout;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user