changeset 18:92d6e1b40df5

Move available extensions into configuration.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 10 Jul 2011 15:48:20 +0200
parents 32f7526da5fe
children 9ff8f951da99
files avatar.js configuration.js.example
diffstat 2 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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: {
--- 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'
+};