# HG changeset patch # User Emmanuel Gil Peyrot # Date 1310303782 -7200 # Node ID 27eaec05cfd042bc8230ba4aacc98fdd33424def # Parent 6689cc444617cd52832a044a2ccc98e4e9358f89 Expire the avatar after a configurable amount of time. diff --git a/avatar.js b/avatar.js --- a/avatar.js +++ b/avatar.js @@ -189,7 +189,8 @@ var getVCard = function(jid, res) { var showImage = function(jid, res) { var extension = jids[jid]; var file = config.directory+'/'+jid+'.'+extension; - res.writeHead(200, {'Content-Type': extensions[extension]}); + var now = new Date; + res.writeHead(200, {'Content-Type': extensions[extension], Expires: new Date(config.expire * 1000 + now.getTime())}); fs.readFile(file, function(err, data) { res.end(data); }); @@ -200,9 +201,8 @@ var showImage = function(jid, res) { } var last = new Date(stats.mtime); - var now = new Date; - if (now - last > 24*60*60*1000) + if (now - last > config.expire * 1000) getVCard(jid, res); }); return; diff --git a/configuration.js.example b/configuration.js.example --- a/configuration.js.example +++ b/configuration.js.example @@ -42,3 +42,6 @@ config.directory = 'data'; // specified. Warning: it doesn’t follow the spec and is only a // workaround for buggy clients. config.guessType = false; + +// Time after which the avatar will be retrieved again, in seconds. +config.expire = 24*60*60;