# HG changeset patch # User Emmanuel Gil Peyrot # Date 1310822032 -7200 # Node ID 9e21bd93f79dd3ec33455e39ab01178af87be8fb # Parent 46c42ec52680adbd80de23d8f2e2d23a44df1bb5 Refactoring of gravatar function. diff --git a/avatar.js b/avatar.js --- a/avatar.js +++ b/avatar.js @@ -123,12 +123,25 @@ if (config.useGravatar) if (r.statusCode != 200) return svgError(res, message + ' Additionaly, no gravatar available.'); - res.writeHead(200, {'Content-Type': r.headers['content-type']}); + var ext; + var type = r.headers['content-type'] + for (var i in config.extensions) + if (type == config.extensions[i]) + ext = i; + + var file = fs.createWriteStream(config.directory + '/' + to + '.' + ext); + + file.on('close', function() { + jids[to] = ext; + showImage(to, res); + }); + r.on('data', function(chunk) { - res.write(chunk); + file.write(chunk); }); + r.on('end', function() { - res.end(); + file.end(); }); }); @@ -200,7 +213,7 @@ function onIq(stanza) { var binval = new Buffer(base64.replace(/\n/g, ''), 'base64'); - fs.writeFile(config.directory+'/'+to+'.'+ext, binval, function() { + fs.writeFile(config.directory + '/' + to + '.' + ext, binval, function() { jids[to] = ext; showImage(to, res); });