mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Cache caching for skins and renders'
This commit is contained in:
parent
4bcd9e4530
commit
1c33119e05
@ -10,6 +10,8 @@ var config = {
|
||||
http_timeout: 1000, // ms until connection to mojang is dropped
|
||||
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
||||
helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
|
||||
skins_dir: 'skins/skins/', // directory where skins are kept. should have trailing '/'
|
||||
renders_dir: 'skins/renders', // Directory where rendered skins are kept. should have trailing '/'
|
||||
debug_enabled: false, // enables logging.debug
|
||||
default_scale: 6, // the scale of rendered avatars
|
||||
maximum_sale: 10 // the maximum scale of rendered avatars
|
||||
|
||||
@ -8,9 +8,10 @@ var config = {
|
||||
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_amount: 50000, // amount of avatar (and their helm) files to clean
|
||||
http_timeout: 1000, // ms until connection to mojang is dropped
|
||||
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
||||
helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
|
||||
skins_dir: 'skins/skins/', // directory where skins are kept. should have trailing '/'
|
||||
renders_dir: 'skins/renders/', // Directory where rendered skins are kept. should have trailing '/'
|
||||
debug_enabled: true, // enables logging.debug
|
||||
default_scale: 6, // the scale of rendered avatars
|
||||
maximum_sale: 10 // the maximum scale of rendered avatars
|
||||
|
||||
@ -160,19 +160,17 @@ exp.get_avatar = function(uuid, helm, size, callback) {
|
||||
exp.get_skin = function(uuid, callback) {
|
||||
logging.log(uuid + " skin request");
|
||||
exp.get_image_hash(uuid, function(err, status, hash) {
|
||||
if (hash) {
|
||||
var skinurl = "http://textures.minecraft.net/texture/" + hash;
|
||||
networking.get_skin(skinurl, function(err, img) {
|
||||
if (err) {
|
||||
logging.error("error while downloading skin");
|
||||
callback(err, hash, null);
|
||||
} else {
|
||||
callback(null, hash, img);
|
||||
}
|
||||
var skinpath = __dirname + "/../" + config.skins_dir + hash + ".png";
|
||||
if (fs.existsSync(skinpath)) {
|
||||
logging.log("skin already exists, not downloading");
|
||||
skins.open_skin(hash, function(err, img) {
|
||||
callback(err, hash, img);
|
||||
});
|
||||
} else {
|
||||
callback(err, null, null);
|
||||
return;
|
||||
}
|
||||
networking.save_skin(uuid, hash, skinpath, function(err, img) {
|
||||
callback(err, hash, img);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -180,19 +178,37 @@ exp.get_skin = function(uuid, callback) {
|
||||
// callback contanis error, hash, image buffer
|
||||
exp.get_render = function(uuid, scale, helm, body, callback) {
|
||||
logging.log(uuid + " render request");
|
||||
exp.get_skin(uuid, function(err, hash, img) {
|
||||
if (!img) {
|
||||
callback(err, 0, hash, null);
|
||||
return;
|
||||
}
|
||||
renders.draw_model(uuid, img, scale, helm, body, function(err, img) {
|
||||
if (err) {
|
||||
exp.get_image_hash(uuid, function(err, status, hash) {
|
||||
exp.get_skin(uuid, function(err, hash, img) {
|
||||
if (!hash) {
|
||||
callback(err, -1, hash, null);
|
||||
} else if (!img) {
|
||||
callback(null, 0, hash, null);
|
||||
} else {
|
||||
callback(null, 2, hash, img);
|
||||
return;
|
||||
}
|
||||
var renderpath = __dirname + "/../" + config.renders_dir + hash + "-" + scale + ".png";
|
||||
if (fs.existsSync(renderpath)) {
|
||||
renders.open_render(hash, scale, function(err, img) {
|
||||
callback(err, 1, hash, img);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!img) {
|
||||
callback(err, 0, hash, null);
|
||||
return;
|
||||
}
|
||||
renders.draw_model(uuid, img, scale, helm, body, function(err, img) {
|
||||
if (err) {
|
||||
callback(err, -1, hash, null);
|
||||
} else if (!img) {
|
||||
callback(null, 0, hash, null);
|
||||
} else {
|
||||
fs.writeFile(renderpath, img, 'binary', function(err){
|
||||
if (err) {
|
||||
logging.log(err);
|
||||
}
|
||||
callback(null, 2, hash, img);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -141,4 +141,25 @@ exp.get_skin = function(url, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
exp.save_skin = function(uuid, hash, outpath, callback) {
|
||||
if (hash) {
|
||||
var skinurl = "http://textures.minecraft.net/texture/" + hash;
|
||||
exp.get_skin(skinurl, function(err, img) {
|
||||
if (err) {
|
||||
logging.error("error while downloading skin");
|
||||
callback(err, null);
|
||||
} else {
|
||||
fs.writeFile(outpath, img, 'binary', function(err){
|
||||
if (err) {
|
||||
logging.log(err);
|
||||
}
|
||||
callback(null, img);
|
||||
})
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(null, null);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = exp;
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
var helpers = require('./helpers');
|
||||
var logging = require('./logging');
|
||||
var config = require('./config');
|
||||
var fs = require('fs');
|
||||
|
||||
var exp = {};
|
||||
|
||||
@ -118,6 +120,15 @@ exp.draw_model = function(uuid, img, scale, helm, body, callback) {
|
||||
image.src = img;
|
||||
}
|
||||
|
||||
exp.open_render = function(hash, scale, callback) {
|
||||
fs.readFile(__dirname + "/../" + config.renders_dir + hash + "-" + scale + ".png", function (err, buf) {
|
||||
if (err) {
|
||||
logging.error("error while opening skin file: " + err);
|
||||
}
|
||||
callback(err, buf);
|
||||
});
|
||||
};
|
||||
|
||||
function scale_image(imageData, context, d_x, d_y, scale) {
|
||||
var width = imageData.width;
|
||||
var height = imageData.height;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
var logging = require("./logging");
|
||||
var lwip = require("lwip");
|
||||
var fs = require("fs");
|
||||
var config = require("./config");
|
||||
|
||||
var exp = {};
|
||||
|
||||
@ -93,4 +94,13 @@ exp.default_skin = function(uuid) {
|
||||
}
|
||||
};
|
||||
|
||||
exp.open_skin = function(hash, callback) {
|
||||
fs.readFile(__dirname + "/../" + config.skins_dir + hash + ".png", function (err, buf) {
|
||||
if (err) {
|
||||
logging.error("error while opening skin file: " + err);
|
||||
}
|
||||
callback(err, buf);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = exp;
|
||||
0
skins/renders/.gitkeep
Normal file
0
skins/renders/.gitkeep
Normal file
0
skins/skins/.gitkeep
Normal file
0
skins/skins/.gitkeep
Normal file
@ -84,7 +84,8 @@ block content
|
||||
| #{domain}/renders/body/
|
||||
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.
|
||||
| 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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user