get rid of redundant config names #124

This commit is contained in:
jomo 2015-06-25 21:19:35 +02:00
parent 20b6fd55aa
commit 34f94bf9b5
7 changed files with 31 additions and 31 deletions

View File

@ -16,15 +16,15 @@ var config = {
amount: 50000 // amount of skins for which all iamge types are deleted
},
directories: {
faces_dir: "images/faces/", // directory where faces are kept. should have trailing "/"
helms_dir: "images/helms/", // directory where helms are kept. should have trailing "/"
skins_dir: "images/skins/", // directory where skins are kept. should have trailing "/"
renders_dir: "images/renders/", // directory where rendered skins are kept. should have trailing "/"
capes_dir: "images/capes/" // directory where capes are kept. should have trailing "/"
faces: "images/faces/", // directory where faces are kept. should have trailing "/"
helms: "images/helms/", // directory where helms are kept. should have trailing "/"
skins: "images/skins/", // directory where skins are kept. should have trailing "/"
renders: "images/renders/", // directory where rendered skins are kept. should have trailing "/"
capes: "images/capes/" // directory where capes are kept. should have trailing "/"
},
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
browser_cache_time: 3600 // seconds until browser will request image again
local: 1200, // seconds until we will check if user's skin changed. should be > 60 to comply with Mojang's rate limit
browser: 3600 // seconds until browser will request image again
},
server: {
http_timeout: 1000, // ms until connection to Mojang is dropped

View File

@ -40,7 +40,7 @@ function connect_redis() {
// the helms file is ignored because we only need 1 file to read/write from
function update_file_date(rid, 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) {
if (exists) {
var date = new Date();
@ -99,7 +99,7 @@ exp.info = function(callback) {
// callback: error
exp.update_timestamp = function(rid, userId, hash, temp, callback) {
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;
// store userId in lower case if not null
userId = userId && userId.toLowerCase();

View File

@ -35,7 +35,7 @@ function should_clean_redis(callback) {
// callback: error, true|false
function should_clean_disk(callback) {
df({
file: path.join(__dirname, "..", config.directories.faces_dir),
file: path.join(__dirname, "..", config.directories.faces),
prefixMultiplier: "KiB",
isDisplayPrefixMultiplier: false,
precision: 2
@ -71,10 +71,10 @@ exp.run = function() {
logging.error(err);
} else if (clean) {
logging.warn("DiskCleaner: Disk limit reached! Cleaning images now");
var facesdir = path.join(__dirname, "..", config.directories.faces_dir);
var helmdir = path.join(__dirname, "..", config.directories.helms_dir);
var renderdir = path.join(__dirname, "..", config.directories.renders_dir);
var skindir = path.join(__dirname, "..", config.directories.skins_dir);
var facesdir = path.join(__dirname, "..", config.directories.faces);
var helmdir = path.join(__dirname, "..", config.directories.helms);
var renderdir = path.join(__dirname, "..", config.directories.renders);
var skindir = path.join(__dirname, "..", config.directories.skins);
fs.readdir(facesdir, function (readerr, files) {
if (!readerr) {
for (var i = 0, l = Math.min(files.length, config.cleaner.amount); i < l; i++) {

View File

@ -30,9 +30,9 @@ function store_skin(rid, userId, profile, cache_details, callback) {
});
} else {
logging.log(rid, "new skin hash:", skin_hash);
var facepath = path.join(__dirname, "..", config.directories.faces_dir, skin_hash + ".png");
var helmpath = path.join(__dirname, "..", config.directories.helms_dir, skin_hash + ".png");
var skinpath = path.join(__dirname, "..", config.directories.skins_dir, skin_hash + ".png");
var facepath = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
var helmpath = path.join(__dirname, "..", config.directories.helms, skin_hash + ".png");
var skinpath = path.join(__dirname, "..", config.directories.skins, skin_hash + ".png");
fs.exists(facepath, function(exists) {
if (exists) {
logging.log(rid, "skin already exists, not downloading");
@ -87,7 +87,7 @@ function store_cape(rid, userId, profile, cache_details, callback) {
});
} else {
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) {
if (exists) {
logging.log(rid, "cape already exists, not downloading");
@ -223,7 +223,7 @@ exp.get_image_hash = function(rid, userId, type, callback) {
if (err) {
callback(err, -1, null);
} 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
logging.log(rid, "userId cached & recently updated");
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_image_hash(rid, userId, "skin", function(err, status, skin_hash) {
if (skin_hash) {
var facepath = path.join(__dirname, "..", config.directories.faces_dir, skin_hash + ".png");
var helmpath = path.join(__dirname, "..", config.directories.helms_dir, skin_hash + ".png");
var facepath = path.join(__dirname, "..", config.directories.faces, skin_hash + ".png");
var helmpath = path.join(__dirname, "..", config.directories.helms, skin_hash + ".png");
var filepath = facepath;
fs.exists(helmpath, function(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_image_hash(rid, userId, "skin", function(err, status, 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) {
if (exists) {
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);
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) {
if (exists) {
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);
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) {
if (exists) {
logging.log(rid, "cape already exists, not downloading");

View File

@ -39,7 +39,7 @@ module.exports = function(request, response, result) {
// These headers are the same for every response
var headers = {
"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,
"X-Request-ID": request.id,
"Access-Control-Allow-Origin": "*"

View File

@ -324,8 +324,8 @@ block content
a(href="#meta-about-caching")
h3 About Caching
p
| Crafatar caches skins for #{config.caching.local_cache_time/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>
| 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/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.

View File

@ -227,7 +227,7 @@ describe("Crafatar", function() {
assert("" + res.headers["response-time"]);
assert(res.headers["x-request-id"]);
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+
@ -895,12 +895,12 @@ describe("Crafatar", function() {
console.log("can't run 'checked' test due to Mojang's rate limits :(");
} else {
it("should be checked", function(done) {
var original_cache_time = config.caching.local_cache_time;
config.caching.local_cache_time = 0;
var original_cache_time = config.caching.local;
config.caching.local = 0;
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
assert.ifError(err);
assert.strictEqual(status, 3);
config.caching.local_cache_time = original_cache_time;
config.caching.local = original_cache_time;
done();
});
});