mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
commit
012f5bf006
18
README.md
18
README.md
@ -8,7 +8,7 @@ Inspired by [Gravatar](https://gravatar.com) (hence the name) and [Minotar](http
|
|||||||
|
|
||||||
Image manipulation is done by [lwip](https://github.com/EyalAr/lwip). 3D renders are created with [node-canvas](https://github.com/Automattic/node-canvas), based on math by [confuser](https://github.com/confuser/serverless-mc-skin-viewer).
|
Image manipulation is done by [lwip](https://github.com/EyalAr/lwip). 3D renders are created with [node-canvas](https://github.com/Automattic/node-canvas), based on math by [confuser](https://github.com/confuser/serverless-mc-skin-viewer).
|
||||||
|
|
||||||
    
|
    
|
||||||
## Usage / Documentation
|
## Usage / Documentation
|
||||||
|
|
||||||
Please [visit the website](https://crafatar.com) for details.
|
Please [visit the website](https://crafatar.com) for details.
|
||||||
@ -45,3 +45,19 @@ Please [visit the website](https://crafatar.com) for details.
|
|||||||
* Start `redis-server`
|
* Start `redis-server`
|
||||||
* `npm start`
|
* `npm start`
|
||||||
* Access [http://localhost:3000](http://localhost:3000)
|
* Access [http://localhost:3000](http://localhost:3000)
|
||||||
|
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
```shell
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to debug failing tests, you can set the env
|
||||||
|
```shell
|
||||||
|
VERBOSE_TEST=true
|
||||||
|
```
|
||||||
|
|
||||||
|
To debug caching, it can be helpful to monitor redis commands while tests are running:
|
||||||
|
```shell
|
||||||
|
redis-cli monitor
|
||||||
|
```
|
||||||
@ -92,11 +92,14 @@ exp.info = function(callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// sets the timestamp for +userId+ and its face file's date to now
|
// sets the timestamp for +userId+ and its face file's (+hash+) date to the current time
|
||||||
|
// if +temp+ is true, the timestamp is set so that the record will be outdated after 60 seconds
|
||||||
|
// these 60 seconds match the duration of Mojang's rate limit ban
|
||||||
// +callback+ contains error
|
// +callback+ contains error
|
||||||
exp.update_timestamp = function(rid, userId, hash, callback) {
|
exp.update_timestamp = function(rid, userId, hash, temp, callback) {
|
||||||
logging.log(rid + "cache: updating timestamp");
|
logging.log(rid + "cache: updating timestamp");
|
||||||
var time = new Date().getTime();
|
sub = temp ? (config.local_cache_time - 60) : 0;
|
||||||
|
var time = new Date().getTime() - sub;
|
||||||
// store userId in lower case if not null
|
// store userId in lower case if not null
|
||||||
userId = userId && userId.toLowerCase();
|
userId = userId && userId.toLowerCase();
|
||||||
redis.hmset(userId, "t", time, function(err) {
|
redis.hmset(userId, "t", time, function(err) {
|
||||||
@ -105,20 +108,31 @@ exp.update_timestamp = function(rid, userId, hash, callback) {
|
|||||||
update_file_date(rid, hash);
|
update_file_date(rid, hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
// create the key +userId+, store +skin_hash+ hash, +cape_hash+ hash and time
|
// create the key +userId+, store +skin_hash+, +cape_hash+ and time
|
||||||
|
// if either +skin_hash+ or +cape_hash+ are undefined, they will not be stored
|
||||||
|
// this feature can be used to write both cape and skin at separate times
|
||||||
// +callback+ contans error
|
// +callback+ contans error
|
||||||
exp.save_hash = function(rid, userId, skin_hash, cape_hash, callback) {
|
exp.save_hash = function(rid, userId, skin_hash, cape_hash, callback) {
|
||||||
logging.log(rid + "cache: saving hash");
|
logging.log(rid + "cache: saving skin:" + skin_hash + " cape:" + cape_hash);
|
||||||
logging.log(rid + "skin:" + skin_hash + " cape:" + cape_hash);
|
|
||||||
var time = new Date().getTime();
|
var time = new Date().getTime();
|
||||||
// store shorter null byte instead of "null"
|
// store shorter null byte instead of "null"
|
||||||
skin_hash = skin_hash || ".";
|
skin_hash = (skin_hash === null ? "" : skin_hash);
|
||||||
cape_hash = cape_hash || ".";
|
cape_hash = (cape_hash === null ? "" : cape_hash);
|
||||||
// store userId in lower case if not null
|
// store userId in lower case if not null
|
||||||
userId = userId && userId.toLowerCase();
|
userId = userId && userId.toLowerCase();
|
||||||
|
if (skin_hash === undefined) {
|
||||||
|
redis.hmset(userId, "c", cape_hash, "t", time, function(err){
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
} else if (cape_hash === undefined) {
|
||||||
|
redis.hmset(userId, "s", skin_hash, "t", time, function(err){
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
redis.hmset(userId, "s", skin_hash, "c", cape_hash, "t", time, function(err){
|
redis.hmset(userId, "s", skin_hash, "c", cape_hash, "t", time, function(err){
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// removes the hash for +userId+ from the cache
|
// removes the hash for +userId+ from the cache
|
||||||
@ -129,7 +143,8 @@ exp.remove_hash = function(rid, userId) {
|
|||||||
|
|
||||||
// get a details object for +userId+
|
// get a details object for +userId+
|
||||||
// {skin: "0123456789abcdef", cape: "gs1gds1g5d1g5ds1", time: 1414881524512}
|
// {skin: "0123456789abcdef", cape: "gs1gds1g5d1g5ds1", time: 1414881524512}
|
||||||
// null when userId unkown
|
// +callback+ contains error, details
|
||||||
|
// details is null when userId not cached
|
||||||
exp.get_details = function(userId, callback) {
|
exp.get_details = function(userId, callback) {
|
||||||
// get userId in lower case if not null
|
// get userId in lower case if not null
|
||||||
userId = userId && userId.toLowerCase();
|
userId = userId && userId.toLowerCase();
|
||||||
@ -137,8 +152,8 @@ exp.get_details = function(userId, callback) {
|
|||||||
var details = null;
|
var details = null;
|
||||||
if (data) {
|
if (data) {
|
||||||
details = {
|
details = {
|
||||||
skin: (data.s === "." ? null : data.s),
|
skin: data.s === "" ? null : data.s,
|
||||||
cape: (data.c === "." ? null : data.c),
|
cape: data.c === "" ? null : data.c,
|
||||||
time: Number(data.t)
|
time: Number(data.t)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,11 @@ function get_hash(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function store_skin(rid, userId, profile, details, callback) {
|
function store_skin(rid, userId, profile, details, callback) {
|
||||||
networking.get_skin_url(rid, userId, profile, function(url) {
|
networking.get_skin_url(rid, userId, profile, function(err, url) {
|
||||||
if (url) {
|
if (!err && url) {
|
||||||
var skin_hash = get_hash(url);
|
var skin_hash = get_hash(url);
|
||||||
if (details && details.skin === skin_hash) {
|
if (details && details.skin === skin_hash) {
|
||||||
cache.update_timestamp(rid, userId, skin_hash, function(err) {
|
cache.update_timestamp(rid, userId, skin_hash, false, function(err) {
|
||||||
callback(err, skin_hash);
|
callback(err, skin_hash);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -41,9 +41,9 @@ function store_skin(rid, userId, profile, details, callback) {
|
|||||||
logging.error(rid + err2.stack);
|
logging.error(rid + err2.stack);
|
||||||
callback(err2, null);
|
callback(err2, null);
|
||||||
} else {
|
} else {
|
||||||
logging.log(rid + "face extracted");
|
logging.debug(rid + "face extracted");
|
||||||
skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
|
skins.extract_helm(rid, facepath, img, helmpath, function(err3) {
|
||||||
logging.log(rid + "helm extracted");
|
logging.debug(rid + "helm extracted");
|
||||||
logging.debug(rid + helmpath);
|
logging.debug(rid + helmpath);
|
||||||
callback(err3, skin_hash);
|
callback(err3, skin_hash);
|
||||||
});
|
});
|
||||||
@ -55,17 +55,17 @@ function store_skin(rid, userId, profile, details, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(null, null);
|
callback(err, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function store_cape(rid, userId, profile, details, callback) {
|
function store_cape(rid, userId, profile, details, callback) {
|
||||||
networking.get_cape_url(rid, userId, profile, function(url) {
|
networking.get_cape_url(rid, userId, profile, function(err, url) {
|
||||||
if (url) {
|
if (!err && url) {
|
||||||
var cape_hash = get_hash(url);
|
var cape_hash = get_hash(url);
|
||||||
if (details && details.cape === cape_hash) {
|
if (details && details.cape === cape_hash) {
|
||||||
cache.update_timestamp(rid, userId, cape_hash, function(err) {
|
cache.update_timestamp(rid, userId, cape_hash, false, function(err) {
|
||||||
callback(err, cape_hash);
|
callback(err, cape_hash);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +82,7 @@ function store_cape(rid, userId, profile, details, callback) {
|
|||||||
callback(err, null);
|
callback(err, null);
|
||||||
} else {
|
} else {
|
||||||
skins.save_image(img, capepath, function(err) {
|
skins.save_image(img, capepath, function(err) {
|
||||||
logging.log(rid + "cape saved");
|
logging.debug(rid + "cape saved");
|
||||||
callback(err, cape_hash);
|
callback(err, cape_hash);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ function store_cape(rid, userId, profile, details, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(null, null);
|
callback(err, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -155,20 +155,30 @@ function store_images(rid, userId, details, type, callback) {
|
|||||||
callback_for(userId, "cape", cache_err, null);
|
callback_for(userId, "cape", cache_err, null);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// an error occured, not caching
|
// an error occured, not caching. we can try in 60 seconds
|
||||||
callback_for(userId, type, err, null);
|
callback_for(userId, type, err, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no error and we have a profile or it's not a uuid
|
// no error and we have a profile (if it's a uuid)
|
||||||
store_skin(rid, userId, profile, details, function(err, skin_hash) {
|
store_skin(rid, userId, profile, details, function(err, skin_hash) {
|
||||||
|
if (err && !skin_hash) {
|
||||||
|
// an error occured, not caching. we can try in 60 seconds
|
||||||
|
callback_for(userId, "skin", err, null);
|
||||||
|
} else {
|
||||||
cache.save_hash(rid, userId, skin_hash, null, function(cache_err) {
|
cache.save_hash(rid, userId, skin_hash, null, function(cache_err) {
|
||||||
callback_for(userId, "skin", (err || cache_err), skin_hash);
|
callback_for(userId, "skin", (err || cache_err), skin_hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
store_cape(rid, userId, profile, details, function(err, cape_hash) {
|
store_cape(rid, userId, profile, details, function(err, cape_hash) {
|
||||||
cache.save_hash(rid, userId, skin_hash, cape_hash, function(cache_err) {
|
if (err && !cape_hash) {
|
||||||
|
// an error occured, not caching. we can try in 60 seconds
|
||||||
|
callback_for(userId, "cape", (err || cache_err), cape_hash);
|
||||||
|
} else {
|
||||||
|
cache.save_hash(rid, userId, undefined, cape_hash, function(cache_err) {
|
||||||
callback_for(userId, "cape", (err || cache_err), cape_hash);
|
callback_for(userId, "cape", (err || cache_err), cape_hash);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -186,7 +196,7 @@ exp.id_valid = function(userId) {
|
|||||||
return valid_user_id.test(userId);
|
return valid_user_id.test(userId);
|
||||||
};
|
};
|
||||||
|
|
||||||
// decides whether to get an image from disk or to download it
|
// decides whether to get a +type+ image for +userId+ from disk or to download it
|
||||||
// callback contains error, status, hash
|
// callback contains error, status, hash
|
||||||
// the status gives information about how the image was received
|
// the status gives information about how the image was received
|
||||||
// -1: "error"
|
// -1: "error"
|
||||||
@ -196,11 +206,11 @@ exp.id_valid = function(userId) {
|
|||||||
// 3: "checked" - profile re-downloaded (was too old), but it has either not changed or has no skin
|
// 3: "checked" - profile re-downloaded (was too old), but it has either not changed or has no skin
|
||||||
exp.get_image_hash = function(rid, userId, type, callback) {
|
exp.get_image_hash = function(rid, userId, type, callback) {
|
||||||
cache.get_details(userId, function(err, details) {
|
cache.get_details(userId, function(err, details) {
|
||||||
var cached_hash = details !== null ? (type === "skin" ? details.skin : details.cape) : null;
|
var cached_hash = (details !== null) ? (type === "skin" ? details.skin : details.cape) : null;
|
||||||
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()) {
|
if (details && details[type] !== undefined && details.time + config.local_cache_time * 1000 >= new Date().getTime()) {
|
||||||
// use cached image
|
// use cached image
|
||||||
logging.log(rid + "userId cached & recently updated");
|
logging.log(rid + "userId cached & recently updated");
|
||||||
callback(null, (cached_hash ? 1 : 0), cached_hash);
|
callback(null, (cached_hash ? 1 : 0), cached_hash);
|
||||||
@ -215,7 +225,9 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
// we might have a cached hash although an error occured
|
// we might have a cached hash although an error occured
|
||||||
// (e.g. Mojang servers not reachable, using outdated hash)
|
// (e.g. Mojang servers not reachable, using outdated hash)
|
||||||
callback(err, -1, details && cached_hash);
|
cache.update_timestamp(rid, userId, cached_hash, true, function(err2) {
|
||||||
|
callback(err2 || err, -1, details && cached_hash);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
var status = details && (cached_hash === new_hash) ? 3 : 2;
|
var status = details && (cached_hash === new_hash) ? 3 : 2;
|
||||||
logging.debug(rid + "cached hash: " + (details && cached_hash));
|
logging.debug(rid + "cached hash: " + (details && cached_hash));
|
||||||
@ -261,7 +273,6 @@ exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|||||||
// handles requests for +userId+ skins
|
// handles requests for +userId+ skins
|
||||||
// callback contains error, skin hash, image buffer
|
// callback contains error, skin hash, image buffer
|
||||||
exp.get_skin = function(rid, userId, callback) {
|
exp.get_skin = function(rid, userId, callback) {
|
||||||
logging.log(rid + "skin request");
|
|
||||||
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
||||||
var skinpath = __dirname + "/../" + config.skins_dir + skin_hash + ".png";
|
var skinpath = __dirname + "/../" + config.skins_dir + skin_hash + ".png";
|
||||||
fs.exists(skinpath, function(exists) {
|
fs.exists(skinpath, function(exists) {
|
||||||
@ -312,7 +323,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|||||||
} else {
|
} else {
|
||||||
fs.writeFile(renderpath, img, "binary", function(err) {
|
fs.writeFile(renderpath, img, "binary", function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.log(rid + err.stack);
|
logging.error(rid + err.stack);
|
||||||
}
|
}
|
||||||
callback(null, 2, skin_hash, img);
|
callback(null, 2, skin_hash, img);
|
||||||
});
|
});
|
||||||
@ -326,7 +337,6 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|||||||
// handles requests for +userId+ capes
|
// handles requests for +userId+ capes
|
||||||
// callback contains error, cape hash, image buffer
|
// callback contains error, cape hash, image buffer
|
||||||
exp.get_cape = function(rid, userId, callback) {
|
exp.get_cape = function(rid, userId, callback) {
|
||||||
logging.log(rid + "cape request");
|
|
||||||
exp.get_image_hash(rid, userId, "cape", function(err, status, cape_hash) {
|
exp.get_image_hash(rid, userId, "cape", function(err, status, cape_hash) {
|
||||||
if (!cape_hash) {
|
if (!cape_hash) {
|
||||||
callback(err, null, null);
|
callback(err, null, null);
|
||||||
|
|||||||
@ -65,6 +65,7 @@ exp.get_from_options = function(rid, url, options, callback) {
|
|||||||
// response received successfully
|
// response received successfully
|
||||||
callback(body, response, null);
|
callback(body, response, null);
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
|
logging.error(error);
|
||||||
callback(body || null, response, error);
|
callback(body || null, response, error);
|
||||||
} else if (code === 404 || code === 204) {
|
} else if (code === 404 || code === 204) {
|
||||||
// page does not exist
|
// page does not exist
|
||||||
@ -128,16 +129,16 @@ exp.get_profile = function(rid, uuid, callback) {
|
|||||||
// get the skin URL for +userId+
|
// get the skin URL for +userId+
|
||||||
// +profile+ is used if +userId+ is a uuid
|
// +profile+ is used if +userId+ is a uuid
|
||||||
exp.get_skin_url = function(rid, userId, profile, callback) {
|
exp.get_skin_url = function(rid, userId, profile, callback) {
|
||||||
get_url(rid, userId, profile, 0, function(url) {
|
get_url(rid, userId, profile, 0, function(err, url) {
|
||||||
callback(url);
|
callback(err, url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// get the cape URL for +userId+
|
// get the cape URL for +userId+
|
||||||
// +profile+ is used if +userId+ is a uuid
|
// +profile+ is used if +userId+ is a uuid
|
||||||
exp.get_cape_url = function(rid, userId, profile, callback) {
|
exp.get_cape_url = function(rid, userId, profile, callback) {
|
||||||
get_url(rid, userId, profile, 1, function(url) {
|
get_url(rid, userId, profile, 1, function(err, url) {
|
||||||
callback(url);
|
callback(err, url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -145,11 +146,11 @@ function get_url(rid, userId, profile, type, callback) {
|
|||||||
if (userId.length <= 16) {
|
if (userId.length <= 16) {
|
||||||
//username
|
//username
|
||||||
exp.get_username_url(rid, userId, type, function(err, url) {
|
exp.get_username_url(rid, userId, type, function(err, url) {
|
||||||
callback(url || null);
|
callback(err, url || null);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exp.get_uuid_url(profile, type, function(url) {
|
exp.get_uuid_url(profile, type, function(url) {
|
||||||
callback(url || null);
|
callback(null, url || null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +165,7 @@ exp.save_texture = function(rid, tex_hash, outpath, callback) {
|
|||||||
} else {
|
} else {
|
||||||
fs.writeFile(outpath, img, "binary", function(err) {
|
fs.writeFile(outpath, img, "binary", function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.log(rid + "error: " + err.stack);
|
logging.error(rid + "error: " + err.stack);
|
||||||
}
|
}
|
||||||
callback(err, response, img);
|
callback(err, response, img);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -150,19 +150,16 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) {
|
|||||||
//Scale it
|
//Scale it
|
||||||
scale_image(skin_ctx.getImageData(0,0,64,original_height), skin_ctx, 0, 0, scale);
|
scale_image(skin_ctx.getImageData(0,0,64,original_height), skin_ctx, 0, 0, scale);
|
||||||
if (body) {
|
if (body) {
|
||||||
logging.log(rid + "drawing body");
|
|
||||||
exp.draw_body(rid, skin_canvas, model_ctx, scale);
|
exp.draw_body(rid, skin_canvas, model_ctx, scale);
|
||||||
}
|
}
|
||||||
logging.log(rid + "drawing head");
|
|
||||||
exp.draw_head(skin_canvas, model_ctx, scale);
|
exp.draw_head(skin_canvas, model_ctx, scale);
|
||||||
if (helm) {
|
if (helm) {
|
||||||
logging.log(rid + "drawing helmet");
|
|
||||||
exp.draw_helmet(skin_canvas, model_ctx, scale);
|
exp.draw_helmet(skin_canvas, model_ctx, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
model_canvas.toBuffer(function(err, buf){
|
model_canvas.toBuffer(function(err, buf){
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.log(rid + "error creating buffer: " + err);
|
logging.error(rid + "error creating buffer: " + err);
|
||||||
}
|
}
|
||||||
callback(err, buf);
|
callback(err, buf);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -53,7 +53,7 @@ exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
|
|||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logging.log(rid + "helm image is the same as face image, not storing!");
|
logging.log(rid + "helm img == face img, not storing!");
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -231,8 +231,8 @@ img.preload {
|
|||||||
.avatar.jomo {background-image: url("/avatars/ae795aa86327408e92ab25c8a59f3ba1?size=64")}
|
.avatar.jomo {background-image: url("/avatars/ae795aa86327408e92ab25c8a59f3ba1?size=64")}
|
||||||
.avatar.jomo:hover {background-image: url("/avatars/ae795aa86327408e92ab25c8a59f3ba1?size=64&helm")}
|
.avatar.jomo:hover {background-image: url("/avatars/ae795aa86327408e92ab25c8a59f3ba1?size=64&helm")}
|
||||||
|
|
||||||
.avatar.jake0oo0 {background-image: url("/avatars/2d5aa9cdaeb049189930461fc9b91cc5?size=64")}
|
.avatar.jake_0 {background-image: url("/avatars/2d5aa9cdaeb049189930461fc9b91cc5?size=64")}
|
||||||
.avatar.jake0oo0:hover {background-image: url("/avatars/2d5aa9cdaeb049189930461fc9b91cc5?size=64&helm")}
|
.avatar.jake_0:hover {background-image: url("/avatars/2d5aa9cdaeb049189930461fc9b91cc5?size=64&helm")}
|
||||||
|
|
||||||
.avatar.sk89q {background-image: url("/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64")}
|
.avatar.sk89q {background-image: url("/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64")}
|
||||||
.avatar.sk89q:hover {background-image: url("/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64&helm")}
|
.avatar.sk89q:hover {background-image: url("/avatars/0ea8eca3dbf647cc9d1ac64551ca975c?size=64&helm")}
|
||||||
|
|||||||
@ -118,7 +118,7 @@ module.exports = function(req, res) {
|
|||||||
// we render the default skins, but not custom images
|
// we render the default skins, but not custom images
|
||||||
renders.draw_model(rid, buf, scale, helm, body, function(err, def_img) {
|
renders.draw_model(rid, buf, scale, helm, body, function(err, def_img) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.log(rid + "error while rendering default image: " + err);
|
logging.error(rid + "error while rendering default image: " + err);
|
||||||
}
|
}
|
||||||
sendimage(rid, http_status, img_status, def_img);
|
sendimage(rid, http_status, img_status, def_img);
|
||||||
});
|
});
|
||||||
|
|||||||
22
test/test.js
22
test/test.js
@ -15,7 +15,9 @@ var request = require("request");
|
|||||||
config.http_timeout *= 3;
|
config.http_timeout *= 3;
|
||||||
|
|
||||||
// no spam
|
// no spam
|
||||||
|
if (process.env.VERBOSE_TEST !== "true") {
|
||||||
logging.log = function() {};
|
logging.log = function() {};
|
||||||
|
}
|
||||||
|
|
||||||
var uuids = fs.readFileSync("test/uuids.txt").toString().split(/\r?\n/);
|
var uuids = fs.readFileSync("test/uuids.txt").toString().split(/\r?\n/);
|
||||||
var names = fs.readFileSync("test/usernames.txt").toString().split(/\r?\n/);
|
var names = fs.readFileSync("test/usernames.txt").toString().split(/\r?\n/);
|
||||||
@ -166,7 +168,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
it("should ignore file updates on invalid files", function(done) {
|
it("should ignore file updates on invalid files", function(done) {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", function(err) {
|
cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", false, function(err) {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -211,7 +213,7 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
it("should return a 422 (invalid size)", function(done) {
|
it("should return a 422 (invalid size)", function(done) {
|
||||||
var size = config.max_size + 1;
|
var size = config.max_size + 1;
|
||||||
request.get("http://localhost:3000/avatars/Jake0oo0?size=" + size, function(error, res, body) {
|
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {
|
||||||
assert.equal(422, res.statusCode);
|
assert.equal(422, res.statusCode);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -219,7 +221,7 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
it("should return a 422 (invalid scale)", function(done) {
|
it("should return a 422 (invalid scale)", function(done) {
|
||||||
var scale = config.max_scale + 1;
|
var scale = config.max_scale + 1;
|
||||||
request.get("http://localhost:3000/renders/head/Jake0oo0?scale=" + scale, function(error, res, body) {
|
request.get("http://localhost:3000/renders/head/Jake_0?scale=" + scale, function(error, res, body) {
|
||||||
assert.equal(422, res.statusCode);
|
assert.equal(422, res.statusCode);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -227,14 +229,14 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
// no default images for capes, should 404
|
// no default images for capes, should 404
|
||||||
it("should return a 404 (no cape)", function(done) {
|
it("should return a 404 (no cape)", function(done) {
|
||||||
request.get("http://localhost:3000/capes/Jake0oo0", function(error, res, body) {
|
request.get("http://localhost:3000/capes/Jake_0", function(error, res, body) {
|
||||||
assert.equal(404, res.statusCode);
|
assert.equal(404, res.statusCode);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return a 422 (invalid render type)", function(done) {
|
it("should return a 422 (invalid render type)", function(done) {
|
||||||
request.get("http://localhost:3000/renders/side/Jake0oo0", function(error, res, body) {
|
request.get("http://localhost:3000/renders/side/Jake_0", function(error, res, body) {
|
||||||
assert.equal(422, res.statusCode);
|
assert.equal(422, res.statusCode);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -246,7 +248,7 @@ describe("Crafatar", function() {
|
|||||||
var location = locations[l];
|
var location = locations[l];
|
||||||
(function(location) {
|
(function(location) {
|
||||||
it("should return a 200 (valid input " + location + ")", function(done) {
|
it("should return a 200 (valid input " + location + ")", function(done) {
|
||||||
request.get("http://localhost:3000/" + location + "/Jake0oo0", function(error, res, body) {
|
request.get("http://localhost:3000/" + location + "/Jake_0", function(error, res, body) {
|
||||||
assert.equal(200, res.statusCode);
|
assert.equal(200, res.statusCode);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -310,7 +312,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not fail (username, 64x64 skin)", function(done) {
|
it("should not fail (username, 64x64 skin)", function(done) {
|
||||||
helpers.get_render(rid, "Jake0oo0", 6, true, true, function(err, hash, img) {
|
helpers.get_render(rid, "Jake_0", 6, true, true, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -334,7 +336,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not be found", function(done) {
|
it("should not be found", function(done) {
|
||||||
helpers.get_cape(rid, "Jake0oo0", function(err, hash, img) {
|
helpers.get_cape(rid, "Jake_0", function(err, hash, img) {
|
||||||
assert.strictEqual(img, null);
|
assert.strictEqual(img, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -343,7 +345,7 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
describe("Networking: Skin", function() {
|
describe("Networking: Skin", function() {
|
||||||
it("should not fail", function(done) {
|
it("should not fail", function(done) {
|
||||||
helpers.get_cape(rid, "Jake0oo0", function(err, hash, img) {
|
helpers.get_cape(rid, "Jake_0", function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -352,7 +354,7 @@ describe("Crafatar", function() {
|
|||||||
before(function() {
|
before(function() {
|
||||||
cache.get_redis().flushall();
|
cache.get_redis().flushall();
|
||||||
});
|
});
|
||||||
helpers.get_cape(rid, "Jake0oo0", function(err, hash, img) {
|
helpers.get_cape(rid, "Jake_0", function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,7 +7,7 @@ block content
|
|||||||
p A blazing fast API for Minecraft faces!
|
p A blazing fast API for Minecraft faces!
|
||||||
.avatar-wrapper
|
.avatar-wrapper
|
||||||
.avatar.jomo(title="jomo's avatar")
|
.avatar.jomo(title="jomo's avatar")
|
||||||
.avatar.jake0oo0(title="jake0oo0's avatar")
|
.avatar.jake_0(title="jake_0's avatar")
|
||||||
.avatar.sk89q(title="sk89q's avatar")
|
.avatar.sk89q(title="sk89q's avatar")
|
||||||
.avatar.md_5(title="md_5's avatar")
|
.avatar.md_5(title="md_5's avatar")
|
||||||
.avatar.notch(title="notch's avatar")
|
.avatar.notch(title="notch's avatar")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user