Mercurial > eldonilo > avatar
changeset 16:27eaec05cfd0
Expire the avatar after a configurable amount of time.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 10 Jul 2011 15:16:22 +0200 |
parents | 6689cc444617 |
children | 32f7526da5fe |
files | avatar.js configuration.js.example |
diffstat | 2 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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;