# HG changeset patch # User Emmanuel Gil Peyrot # Date 1310305700 -7200 # Node ID 92d6e1b40df54abce407b49f3aab93cef468c78f # Parent 32f7526da5fe6b19e92063c304acd2a549f73221 Move available extensions into configuration. diff --git a/avatar.js b/avatar.js --- a/avatar.js +++ b/avatar.js @@ -65,13 +65,6 @@ var getUniqueId = (function() { }; })(); -var extensions = { - png: 'image/png', - svg: 'image/svg+xml', - jpg: 'image/jpeg', - gif: 'image/gif' -} - var jids = {}; var sent = {}; @@ -138,8 +131,8 @@ function onIq(stanza) { } var ext; - for (var i in extensions) - if (type == extensions[i]) + for (var i in config.extensions) + if (type == config.extensions[i]) ext = i; // Here we don’t try to guess the extension even if the option is set. @@ -190,7 +183,7 @@ var showImage = function(jid, res) { var extension = jids[jid]; var file = config.directory+'/'+jid+'.'+extension; var now = new Date; - res.writeHead(200, {'Content-Type': extensions[extension], Expires: new Date(config.expire * 1000 + now.getTime())}); + res.writeHead(200, {'Content-Type': config.extensions[extension], Expires: new Date(config.expire * 1000 + now.getTime())}); fs.readFile(file, function(err, data) { res.end(data); }); @@ -219,7 +212,7 @@ fs.readdir(config.directory, function(er }); http.createServer(function (req, res) { - console.log('Connection from ' + (req.headers['x-forwarded-for'] || req.client.remoteAddress) + ' (' + req.headers['user-agent'] + ') to get “' + req.url + '”.'); + console.log('Connection from ' + (req.headers['x-forwarded-for'] || req.client.remoteAddress) + ' (' + req.headers['user-agent'] + ') to ' + req.method.toLocaleLowerCase() + ' “' + req.url + '”.'); var easterEggs = { source: { diff --git a/configuration.js.example b/configuration.js.example --- a/configuration.js.example +++ b/configuration.js.example @@ -45,3 +45,11 @@ config.guessType = false; // Time after which the avatar will be retrieved again, in seconds. config.expire = 24*60*60; + +// Allowed extensions, associated with their MIME type. +config.extensions = { + png: 'image/png', + svg: 'image/svg+xml', + jpg: 'image/jpeg', + gif: 'image/gif' +};