Skip to content

Commit

Permalink
GET /stats
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Dec 18, 2011
1 parent dfafe67 commit 4215d10
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions routes.js
Expand Up @@ -5,7 +5,8 @@ var rasterize = require('./lib/rasterize')
, join = path.join
, fs = require('fs');

var dir = app.get('screenshots');
var dir = app.get('screenshots')
, db = app.db;

/*
* GET home page.
Expand All @@ -20,18 +21,29 @@ app.get('/', function(req, res, next){
* GET screenshot.
*/

app.get('/', function(req, res){
app.get('/', function(req, res, next){
var url = req.query.url;
if (!url) return res.send(400);
var id = md5(url);
var path = join(dir, id + '.png');
rasterize(url, path, function(err){
if (err) return res.send(500, 'Something broke!\n');
if (err) return next(err);
app.emit('screenshot', path, id);
res.sendfile(path);
});
});

/**
* GET stats.
*/

app.get('/stats', function(req, res){
db.hgetall('screenshot:stats', function(err, obj){
if (err) return next(err);
res.send(obj);
});
});

/**
* MD5 the given `str`.
*/
Expand Down

0 comments on commit 4215d10

Please sign in to comment.