mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
get rid of redundant config names #124
This commit is contained in:
parent
20b6fd55aa
commit
34f94bf9b5
@ -16,15 +16,15 @@ var config = {
|
|||||||
amount: 50000 // amount of skins for which all iamge types are deleted
|
amount: 50000 // amount of skins for which all iamge types are deleted
|
||||||
},
|
},
|
||||||
directories: {
|
directories: {
|
||||||
faces_dir: "images/faces/", // directory where faces are kept. should have trailing "/"
|
faces: "images/faces/", // directory where faces are kept. should have trailing "/"
|
||||||
helms_dir: "images/helms/", // directory where helms are kept. should have trailing "/"
|
helms: "images/helms/", // directory where helms are kept. should have trailing "/"
|
||||||
skins_dir: "images/skins/", // directory where skins are kept. should have trailing "/"
|
skins: "images/skins/", // directory where skins are kept. should have trailing "/"
|
||||||
renders_dir: "images/renders/", // directory where rendered skins are kept. should have trailing "/"
|
renders: "images/renders/", // directory where rendered skins are kept. should have trailing "/"
|
||||||
capes_dir: "images/capes/" // directory where capes are kept. should have trailing "/"
|
capes: "images/capes/" // directory where capes are kept. should have trailing "/"
|
||||||
},
|
},
|
||||||
caching: {
|
caching: {
|
||||||
local_cache_time: 1200, // seconds until we will check if user's skin changed. should be > 60 to comply with Mojang's rate limit
|
local: 1200, // seconds until we will check if user's skin changed. should be > 60 to comply with Mojang's rate limit
|
||||||
browser_cache_time: 3600 // seconds until browser will request image again
|
browser: 3600 // seconds until browser will request image again
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
http_timeout: 1000, // ms until connection to Mojang is dropped
|
http_timeout: 1000, // ms until connection to Mojang is dropped
|
||||||
|
|||||||
@ -40,7 +40,7 @@ function connect_redis() {
|
|||||||
// the helms file is ignored because we only need 1 file to read/write from
|
// the helms file is ignored because we only need 1 file to read/write from
|
||||||
function update_file_date(rid, skin_hash) {
|
function update_file_date(rid, skin_hash) {
|
||||||
if (skin_hash) {
|
if (skin_hash) {
|
||||||
var face_path = path.join(__dirname, "..", config.directories.faces_dir, skin_hash + ".png");
|
var face_path = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
|
||||||
fs.exists(face_path, function(exists) {
|
fs.exists(face_path, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
@ -99,7 +99,7 @@ exp.info = function(callback) {
|
|||||||
// callback: error
|
// callback: error
|
||||||
exp.update_timestamp = function(rid, userId, hash, temp, callback) {
|
exp.update_timestamp = function(rid, userId, hash, temp, callback) {
|
||||||
logging.debug(rid, "updating cache timestamp");
|
logging.debug(rid, "updating cache timestamp");
|
||||||
var sub = temp ? (config.caching.local_cache_time - 60) : 0;
|
var sub = temp ? (config.caching.local - 60) : 0;
|
||||||
var time = Date.now() - sub;
|
var time = Date.now() - 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();
|
||||||
|
|||||||
@ -35,7 +35,7 @@ function should_clean_redis(callback) {
|
|||||||
// callback: error, true|false
|
// callback: error, true|false
|
||||||
function should_clean_disk(callback) {
|
function should_clean_disk(callback) {
|
||||||
df({
|
df({
|
||||||
file: path.join(__dirname, "..", config.directories.faces_dir),
|
file: path.join(__dirname, "..", config.directories.faces),
|
||||||
prefixMultiplier: "KiB",
|
prefixMultiplier: "KiB",
|
||||||
isDisplayPrefixMultiplier: false,
|
isDisplayPrefixMultiplier: false,
|
||||||
precision: 2
|
precision: 2
|
||||||
@ -71,10 +71,10 @@ exp.run = function() {
|
|||||||
logging.error(err);
|
logging.error(err);
|
||||||
} else if (clean) {
|
} else if (clean) {
|
||||||
logging.warn("DiskCleaner: Disk limit reached! Cleaning images now");
|
logging.warn("DiskCleaner: Disk limit reached! Cleaning images now");
|
||||||
var facesdir = path.join(__dirname, "..", config.directories.faces_dir);
|
var facesdir = path.join(__dirname, "..", config.directories.faces);
|
||||||
var helmdir = path.join(__dirname, "..", config.directories.helms_dir);
|
var helmdir = path.join(__dirname, "..", config.directories.helms);
|
||||||
var renderdir = path.join(__dirname, "..", config.directories.renders_dir);
|
var renderdir = path.join(__dirname, "..", config.directories.renders);
|
||||||
var skindir = path.join(__dirname, "..", config.directories.skins_dir);
|
var skindir = path.join(__dirname, "..", config.directories.skins);
|
||||||
fs.readdir(facesdir, function (readerr, files) {
|
fs.readdir(facesdir, function (readerr, files) {
|
||||||
if (!readerr) {
|
if (!readerr) {
|
||||||
for (var i = 0, l = Math.min(files.length, config.cleaner.amount); i < l; i++) {
|
for (var i = 0, l = Math.min(files.length, config.cleaner.amount); i < l; i++) {
|
||||||
|
|||||||
@ -30,9 +30,9 @@ function store_skin(rid, userId, profile, cache_details, callback) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logging.log(rid, "new skin hash:", skin_hash);
|
logging.log(rid, "new skin hash:", skin_hash);
|
||||||
var facepath = path.join(__dirname, "..", config.directories.faces_dir, skin_hash + ".png");
|
var facepath = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
|
||||||
var helmpath = path.join(__dirname, "..", config.directories.helms_dir, skin_hash + ".png");
|
var helmpath = path.join(__dirname, "..", config.directories.helms, skin_hash + ".png");
|
||||||
var skinpath = path.join(__dirname, "..", config.directories.skins_dir, skin_hash + ".png");
|
var skinpath = path.join(__dirname, "..", config.directories.skins, skin_hash + ".png");
|
||||||
fs.exists(facepath, function(exists) {
|
fs.exists(facepath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
logging.log(rid, "skin already exists, not downloading");
|
logging.log(rid, "skin already exists, not downloading");
|
||||||
@ -87,7 +87,7 @@ function store_cape(rid, userId, profile, cache_details, callback) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logging.log(rid, "new cape hash:", cape_hash);
|
logging.log(rid, "new cape hash:", cape_hash);
|
||||||
var capepath = path.join(__dirname, "..", config.directories.capes_dir, cape_hash + ".png");
|
var capepath = path.join(__dirname, "..", config.directories.capes, cape_hash + ".png");
|
||||||
fs.exists(capepath, function(exists) {
|
fs.exists(capepath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
logging.log(rid, "cape already exists, not downloading");
|
logging.log(rid, "cape already exists, not downloading");
|
||||||
@ -223,7 +223,7 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
callback(err, -1, null);
|
callback(err, -1, null);
|
||||||
} else {
|
} else {
|
||||||
if (cache_details && cache_details[type] !== undefined && cache_details.time + config.caching.local_cache_time * 1000 >= Date.now()) {
|
if (cache_details && cache_details[type] !== undefined && cache_details.time + config.caching.local * 1000 >= Date.now()) {
|
||||||
// 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);
|
||||||
@ -261,8 +261,8 @@ exp.get_image_hash = function(rid, userId, type, callback) {
|
|||||||
exp.get_avatar = function(rid, userId, helm, size, callback) {
|
exp.get_avatar = function(rid, userId, helm, size, callback) {
|
||||||
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
||||||
if (skin_hash) {
|
if (skin_hash) {
|
||||||
var facepath = path.join(__dirname, "..", config.directories.faces_dir, skin_hash + ".png");
|
var facepath = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
|
||||||
var helmpath = path.join(__dirname, "..", config.directories.helms_dir, skin_hash + ".png");
|
var helmpath = path.join(__dirname, "..", config.directories.helms, skin_hash + ".png");
|
||||||
var filepath = facepath;
|
var filepath = facepath;
|
||||||
fs.exists(helmpath, function(exists) {
|
fs.exists(helmpath, function(exists) {
|
||||||
if (helm && exists) {
|
if (helm && exists) {
|
||||||
@ -288,7 +288,7 @@ exp.get_avatar = function(rid, userId, helm, size, callback) {
|
|||||||
exp.get_skin = function(rid, userId, callback) {
|
exp.get_skin = function(rid, userId, callback) {
|
||||||
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
exp.get_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
|
||||||
if (skin_hash) {
|
if (skin_hash) {
|
||||||
var skinpath = path.join(__dirname, "..", config.directories.skins_dir, skin_hash + ".png");
|
var skinpath = path.join(__dirname, "..", config.directories.skins, skin_hash + ".png");
|
||||||
fs.exists(skinpath, function(exists) {
|
fs.exists(skinpath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
logging.log(rid, "skin already exists, not downloading");
|
logging.log(rid, "skin already exists, not downloading");
|
||||||
@ -323,7 +323,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) {
|
|||||||
callback(err, status, skin_hash, null);
|
callback(err, status, skin_hash, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var renderpath = path.join(__dirname, "..", config.directories.renders_dir, [skin_hash, scale, get_type(helm, body)].join("-") + ".png");
|
var renderpath = path.join(__dirname, "..", config.directories.renders, [skin_hash, scale, get_type(helm, body)].join("-") + ".png");
|
||||||
fs.exists(renderpath, function(exists) {
|
fs.exists(renderpath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
renders.open_render(rid, renderpath, function(render_err, rendered_img) {
|
renders.open_render(rid, renderpath, function(render_err, rendered_img) {
|
||||||
@ -362,7 +362,7 @@ exp.get_cape = function(rid, userId, callback) {
|
|||||||
callback(err, null, status, null);
|
callback(err, null, status, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var capepath = path.join(__dirname, "..", config.directories.capes_dir, cape_hash + ".png");
|
var capepath = path.join(__dirname, "..", config.directories.capes, cape_hash + ".png");
|
||||||
fs.exists(capepath, function(exists) {
|
fs.exists(capepath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
logging.log(rid, "cape already exists, not downloading");
|
logging.log(rid, "cape already exists, not downloading");
|
||||||
|
|||||||
@ -39,7 +39,7 @@ module.exports = function(request, response, result) {
|
|||||||
// These headers are the same for every response
|
// These headers are the same for every response
|
||||||
var headers = {
|
var headers = {
|
||||||
"Content-Type": (result.body && result.type) || "text/plain",
|
"Content-Type": (result.body && result.type) || "text/plain",
|
||||||
"Cache-Control": "max-age=" + config.caching.browser_cache_time + ", public",
|
"Cache-Control": "max-age=" + config.caching.browser + ", public",
|
||||||
"Response-Time": Date.now() - request.start,
|
"Response-Time": Date.now() - request.start,
|
||||||
"X-Request-ID": request.id,
|
"X-Request-ID": request.id,
|
||||||
"Access-Control-Allow-Origin": "*"
|
"Access-Control-Allow-Origin": "*"
|
||||||
|
|||||||
@ -324,8 +324,8 @@ block content
|
|||||||
a(href="#meta-about-caching")
|
a(href="#meta-about-caching")
|
||||||
h3 About Caching
|
h3 About Caching
|
||||||
p
|
p
|
||||||
| Crafatar caches skins for #{config.caching.local_cache_time/60} minutes before checking for skin changes.<br>
|
| Crafatar caches skins for #{config.caching.local/60} minutes before checking for skin changes.<br>
|
||||||
| Images are cached in your browser for #{config.caching.browser_cache_time/60} minutes until a new request to Crafatar is made.<br>
|
| Images are cached in your browser for #{config.caching.browser/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.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -227,7 +227,7 @@ describe("Crafatar", function() {
|
|||||||
assert("" + res.headers["response-time"]);
|
assert("" + res.headers["response-time"]);
|
||||||
assert(res.headers["x-request-id"]);
|
assert(res.headers["x-request-id"]);
|
||||||
assert.equal(res.headers["access-control-allow-origin"], "*");
|
assert.equal(res.headers["access-control-allow-origin"], "*");
|
||||||
assert.equal(res.headers["cache-control"], "max-age=" + config.caching.browser_cache_time + ", public");
|
assert.equal(res.headers["cache-control"], "max-age=" + config.caching.browser + ", public");
|
||||||
}
|
}
|
||||||
|
|
||||||
// throws Exception when +url+ is requested with +etag+
|
// throws Exception when +url+ is requested with +etag+
|
||||||
@ -895,12 +895,12 @@ describe("Crafatar", function() {
|
|||||||
console.log("can't run 'checked' test due to Mojang's rate limits :(");
|
console.log("can't run 'checked' test due to Mojang's rate limits :(");
|
||||||
} else {
|
} else {
|
||||||
it("should be checked", function(done) {
|
it("should be checked", function(done) {
|
||||||
var original_cache_time = config.caching.local_cache_time;
|
var original_cache_time = config.caching.local;
|
||||||
config.caching.local_cache_time = 0;
|
config.caching.local = 0;
|
||||||
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(status, 3);
|
assert.strictEqual(status, 3);
|
||||||
config.caching.local_cache_time = original_cache_time;
|
config.caching.local = original_cache_time;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user