mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Merge branch 'master' of github.com:Jake0oo0/crafatar
This commit is contained in:
commit
5bc1831644
@ -51,10 +51,22 @@ function update_file_date(hash) {
|
|||||||
|
|
||||||
var exp = {};
|
var exp = {};
|
||||||
|
|
||||||
|
// returns the redis instance
|
||||||
exp.get_redis = function() {
|
exp.get_redis = function() {
|
||||||
return redis;
|
return redis;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// updates the redis instance's server_info object
|
||||||
|
// callback contains error, info object
|
||||||
|
exp.info = function(callback) {
|
||||||
|
redis.info(function (err, res) {
|
||||||
|
// parse the info command and store it in redis.server_info
|
||||||
|
redis.on_info_cmd(err, res);
|
||||||
|
callback(err, redis.server_info);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// sets the timestamp for +uuid+ and its face file's date to now
|
// sets the timestamp for +uuid+ and its face file's date to now
|
||||||
exp.update_timestamp = function(uuid, hash) {
|
exp.update_timestamp = function(uuid, hash) {
|
||||||
logging.log(uuid + " cache: updating timestamp");
|
logging.log(uuid + " cache: updating timestamp");
|
||||||
|
|||||||
@ -1,13 +1,35 @@
|
|||||||
var logging = require("./logging");
|
var logging = require("./logging");
|
||||||
var config = require("./config");
|
var config = require("./config");
|
||||||
|
var cache = require("./cache");
|
||||||
var df = require("node-df");
|
var df = require("node-df");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
|
var redis = cache.get_redis();
|
||||||
var exp = {};
|
var exp = {};
|
||||||
|
|
||||||
|
// compares redis' used_memory with cleaning_redis_limit
|
||||||
|
// callback contains error, true|false
|
||||||
|
function should_clean_redis(callback) {
|
||||||
|
cache.info(function(err, info) {
|
||||||
|
if (err) {
|
||||||
|
callback(err, false);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
logging.debug(info);
|
||||||
|
logging.debug("used mem:" + info.used_memory);
|
||||||
|
var used = parseInt(info.used_memory) / 1024;
|
||||||
|
logging.log("RedisCleaner: " + used + "KB used");
|
||||||
|
callback(err, used >= config.cleaning_redis_limit);
|
||||||
|
} catch(e) {
|
||||||
|
callback(e, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// uses `df` to get the available fisk space
|
// uses `df` to get the available fisk space
|
||||||
// callback contains error, true|false
|
// callback contains error, true|false
|
||||||
function should_clean(callback) {
|
function should_clean_disk(callback) {
|
||||||
df({
|
df({
|
||||||
file: __dirname + "/../" + config.faces_dir,
|
file: __dirname + "/../" + config.faces_dir,
|
||||||
prefixMultiplier: 'KiB',
|
prefixMultiplier: 'KiB',
|
||||||
@ -18,21 +40,33 @@ function should_clean(callback) {
|
|||||||
callback(err, false);
|
callback(err, false);
|
||||||
} else {
|
} else {
|
||||||
var available = response[0].available;
|
var available = response[0].available;
|
||||||
console.log("ImageCleaner: " + available + "KB available");
|
logging.log("DiskCleaner: " + available + "KB available");
|
||||||
callback(err, available < config.cleaning_limit);
|
callback(err, available < config.cleaning_disk_limit);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if disk limit reached
|
// check if redis limit reached, then flush redis
|
||||||
// then delete images
|
// check if disk limit reached, then delete images
|
||||||
exp.run = function() {
|
exp.run = function() {
|
||||||
should_clean(function(err, clean) {
|
should_clean_redis(function(err, clean) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.error("Failed to run ImageCleaner");
|
logging.error("Failed to run RedisCleaner");
|
||||||
logging.error(err);
|
logging.error(err);
|
||||||
} else if (clean) {
|
} else if (clean) {
|
||||||
logging.warn("ImageCleaner: Disk limit reached! Cleaning images now");
|
logging.warn("RedisCleaner: Redis limit reached! flushing now");
|
||||||
|
redis.flushall();
|
||||||
|
} else {
|
||||||
|
logging.log("RedisCleaner: Nothing to clean");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
should_clean_disk(function(err, clean) {
|
||||||
|
if (err) {
|
||||||
|
logging.error("Failed to run DiskCleaner");
|
||||||
|
logging.error(err);
|
||||||
|
} else if (clean) {
|
||||||
|
logging.warn("DiskCleaner: Disk limit reached! Cleaning images now");
|
||||||
var facesdir = __dirname + "/../" + config.faces_dir;
|
var facesdir = __dirname + "/../" + config.faces_dir;
|
||||||
var helmdir = __dirname + "/../" + config.helms_dir;
|
var helmdir = __dirname + "/../" + config.helms_dir;
|
||||||
var renderdir = __dirname + "/../" + config.renders_dir;
|
var renderdir = __dirname + "/../" + config.renders_dir;
|
||||||
@ -54,7 +88,7 @@ exp.run = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.log("ImageCleaner: Nothing to clean");
|
logging.log("DiskCleaner: Nothing to clean");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -5,7 +5,8 @@ var config = {
|
|||||||
local_cache_time: 1200, // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
|
local_cache_time: 1200, // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
|
||||||
browser_cache_time: 3600, // seconds until browser will request image again
|
browser_cache_time: 3600, // seconds until browser will request image again
|
||||||
cleaning_interval: 1800, // seconds interval: deleting images if disk size at limit
|
cleaning_interval: 1800, // seconds interval: deleting images if disk size at limit
|
||||||
cleaning_limit: 10240, // minumum required available KB on disk to trigger cleaning
|
cleaning_disk_limit: 10240, // min allowed available KB on disk to trigger cleaning
|
||||||
|
cleaning_redis_limit: 24576, // max allowed used KB on redis to trigger redis flush
|
||||||
cleaning_amount: 50000, // amount of avatar (and their helm) files to clean
|
cleaning_amount: 50000, // amount of avatar (and their helm) files to clean
|
||||||
http_timeout: 1000, // ms until connection to mojang is dropped
|
http_timeout: 1000, // ms until connection to mojang is dropped
|
||||||
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
var config = require("./modules/config");
|
var config = require("./modules/config");
|
||||||
var debug = require("debug")("crafatar");
|
var debug = require("debug")("crafatar");
|
||||||
var clean = require("./modules/clean_images");
|
var clean = require("./modules/cleaner");
|
||||||
var app = require("./app");
|
var app = require("./app");
|
||||||
|
|
||||||
app.set("port", process.env.PORT || 3000);
|
app.set("port", process.env.PORT || 3000);
|
||||||
|
|||||||
@ -27,17 +27,13 @@ block content
|
|||||||
mark.green id
|
mark.green id
|
||||||
|
|
|
|
||||||
|
|
||||||
a(id="parameters", class="anchor")
|
a(id="avatar-parameters", class="anchor")
|
||||||
a(href="#parameters")
|
a(href="#avatar-parameters")
|
||||||
h3 Parameters
|
h3 Avatar Parameters
|
||||||
a(id="size", class="anchor")
|
|
||||||
a(href="#size")
|
|
||||||
h4 size
|
h4 size
|
||||||
p
|
p
|
||||||
| The size of the image in pixels, #{config.min_size} - #{config.max_size}.<br>
|
| The size of the image in pixels, #{config.min_size} - #{config.max_size}.<br>
|
||||||
| Default is #{config.default_size}.
|
| Default is #{config.default_size}.
|
||||||
a(id="default", class="anchor")
|
|
||||||
a(href="#default")
|
|
||||||
h4 default
|
h4 default
|
||||||
p
|
p
|
||||||
| The image to be served when the id has no skin (404).<br>
|
| The image to be served when the id has no skin (404).<br>
|
||||||
@ -46,60 +42,65 @@ block content
|
|||||||
| ,
|
| ,
|
||||||
a(href="/avatars/00000000000000000000000000000000?default=alex") alex
|
a(href="/avatars/00000000000000000000000000000000?default=alex") alex
|
||||||
| , or a custom URL.<br>
|
| , or a custom URL.<br>
|
||||||
| The standard value is calculated based on the id (even = alex, odd = steve)
|
| The standard value is calculated based on the UUID (even = alex, odd = steve). Usernames always default to steve.
|
||||||
a(id="helm", class="anchor")
|
|
||||||
a(href="#helm")
|
|
||||||
h4 helm
|
h4 helm
|
||||||
p
|
p
|
||||||
| Get an avatar with the "second" (hat) layer applied.<br>
|
| Apply the "second" (hat) layer to the avatar.<br>
|
||||||
| The content of this parameter can be anything.<br>
|
| The content of this parameter is ignored.<br>
|
||||||
| If you want to get the face only, remove the parameter.
|
| If you want to get the face only, remove the parameter.
|
||||||
|
|
||||||
a(id="skins", class="anchor")
|
a(id="skins", class="anchor")
|
||||||
a(href="#skins")
|
a(href="#skins")
|
||||||
h3 Skins
|
h3 Skins
|
||||||
p
|
p
|
||||||
| You can also get the full skin file from name or id.<br>
|
| You can also get the full skin file of a player.<br>
|
||||||
| Replace
|
| Replace
|
||||||
mark.green id
|
mark.green id
|
||||||
| with a Mojang <b>UUID</b> or <b>username</b> to get the related skin.
|
| with a Mojang <b>UUID</b> or <b>username</b> to get the related skin.<br>
|
||||||
| The user's skin will be returned, or the default image is served.<br>
|
| The user's skin is returned, or the default image is served.<br>
|
||||||
| You can use the default parameter here as well.
|
| You can use the default parameter here as well.
|
||||||
.code
|
.code
|
||||||
| #{domain}/skins/
|
| #{domain}/skins/
|
||||||
mark.green id
|
mark.green id
|
||||||
|
|
||||||
|
a(id="skin-parameters", class="anchor")
|
||||||
|
a(href="#skin-parameters")
|
||||||
|
h3 Skin Parameters
|
||||||
|
h4 default
|
||||||
|
p
|
||||||
|
| Same as the default for avatars.
|
||||||
|
|
||||||
a(id="renders", class="anchor")
|
a(id="renders", class="anchor")
|
||||||
a(href="renders")
|
a(href="#renders")
|
||||||
h3 3D Renders
|
h3 3D Renders
|
||||||
p
|
p
|
||||||
| Crafatar also provides support for 3D renders of Minecraft skins.
|
| Crafatar also provides support for 3D renders of Minecraft skins.<br>
|
||||||
|
| Please note that <b>this feature is currently beta</b>!<br>
|
||||||
| Replace
|
| Replace
|
||||||
mark.green id
|
mark.green id
|
||||||
| with a Mojang <b>UUID</b> or <b>username</b> to get an render for the skin.
|
| with a Mojang <b>UUID</b> or <b>username</b> to get a render of the skin.
|
||||||
|
| The <b>head</b> render type returns a render of the skin's head.
|
||||||
.code
|
.code
|
||||||
| #{domain}/renders/head/
|
| #{domain}/renders/head/
|
||||||
mark.green id
|
mark.green id
|
||||||
|
| The <b>body</b> render returns a render of the entire skin.
|
||||||
.code
|
.code
|
||||||
| #{domain}/renders/body/
|
| #{domain}/renders/body/
|
||||||
mark.green id
|
mark.green id
|
||||||
| The <b>default</b> parameter can also be used here. Using alex or steve will create a
|
|
||||||
| render with the same parameters. A custom image will not be rendered. A UUID or username
|
|
||||||
| without a skin, will produce a render based on the input id, or the <b>default</b> parameter.
|
|
||||||
| Using the <b>helm</b> parameter is also allowed, which will be overlayed onto the head.
|
|
||||||
| The <b>head</b> render type will return only a render of the skin's head, while the
|
|
||||||
| <b>body</b> render will return a render of the entire skin.
|
|
||||||
|
|
||||||
a(id="#render-parameters", class="#render-anchor")
|
a(id="render-parameters", class="anchor")
|
||||||
a(href="#render-parameters")
|
a(href="#render-parameters")
|
||||||
h3 Render Parameters
|
h3 Render Parameters
|
||||||
a(id="scale", class="anchor")
|
|
||||||
a(href="#scale")
|
|
||||||
h4 scale
|
h4 scale
|
||||||
p
|
p
|
||||||
| The scale factor of the image #{config.min_scale} - #{config.max_scale}.<br>
|
| The scale factor of the image #{config.min_scale} - #{config.max_scale}.<br>
|
||||||
| Default is #{config.default_scale}. The actual size differs between the type of render.
|
| Default is #{config.default_scale}. The actual size differs between the type of render.
|
||||||
|
h4 helm
|
||||||
|
p
|
||||||
|
| Same as the helm for avatars, but it does not stand out (as it does ingame).
|
||||||
|
h4 default
|
||||||
|
p
|
||||||
|
| Same as the default for avatars.
|
||||||
|
|
||||||
a(id="http-headers", class="anchor")
|
a(id="http-headers", class="anchor")
|
||||||
a(href="#http-headers")
|
a(href="#http-headers")
|
||||||
@ -149,9 +150,12 @@ block content
|
|||||||
| Images are cached in your browser for #{config.browser_cache_time/60} minutes until a new request to Crafatar is made.<br>
|
| Images are cached in your browser for #{config.browser_cache_time/60} minutes until a new request to Crafatar is made.<br>
|
||||||
| When you changed your skin you can try clearing your browser cache to see the change faster.
|
| When you changed your skin you can try clearing your browser cache to see the change faster.
|
||||||
|
|
||||||
|
|
||||||
a(id="examples", class="anchor")
|
a(id="examples", class="anchor")
|
||||||
a(href="#examples")
|
a(href="#examples")
|
||||||
h3 Examples
|
h3 Examples
|
||||||
|
|
||||||
|
h4 Avatars
|
||||||
p Jeb's avatar by username, default size
|
p Jeb's avatar by username, default size
|
||||||
.code #{domain}/avatars/jeb_
|
.code #{domain}/avatars/jeb_
|
||||||
p Jeb's avatar by UUID, default size
|
p Jeb's avatar by UUID, default size
|
||||||
@ -166,14 +170,20 @@ block content
|
|||||||
| Jeb's avatar, or fall back to
|
| Jeb's avatar, or fall back to
|
||||||
a(href="https://i.imgur.com/ozszMZV.png") a custom image
|
a(href="https://i.imgur.com/ozszMZV.png") a custom image
|
||||||
.code #{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?default=https%3A%2F%2Fi.imgur.com%2FozszMZV.png
|
.code #{domain}/avatars/853c80ef3c3749fdaa49938b674adae6?default=https%3A%2F%2Fi.imgur.com%2FozszMZV.png
|
||||||
|
|
||||||
|
h4 Skins
|
||||||
p Jeb's skin
|
p Jeb's skin
|
||||||
.code #{domain}/skins/853c80ef3c3749fdaa49938b674adae6
|
.code #{domain}/skins/853c80ef3c3749fdaa49938b674adae6
|
||||||
p Jeb's skin by username
|
p Jeb's skin by username
|
||||||
.code #{domain}/skins/jeb_
|
.code #{domain}/skins/jeb_
|
||||||
p Render of Jeb's Head
|
p Render of Jeb's Head
|
||||||
|
|
||||||
|
h4 Renders
|
||||||
.code #{domain}/renders/head/853c80ef3c3749fdaa49938b674adae6
|
.code #{domain}/renders/head/853c80ef3c3749fdaa49938b674adae6
|
||||||
p Render of Jeb's Body, with helmet, by username
|
p Render of Jeb's Body, with helmet, by username
|
||||||
.code #{domain}/renders/body/jeb_?helm
|
.code #{domain}/renders/body/jeb_?helm
|
||||||
|
|
||||||
|
|
||||||
.col-md-2.center
|
.col-md-2.center
|
||||||
.sideface.redstone_sheep(title="redstone_sheep")
|
.sideface.redstone_sheep(title="redstone_sheep")
|
||||||
.sideface.Jake0oo0(title="Jake0oo0")
|
.sideface.Jake0oo0(title="Jake0oo0")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user