Permalink
Browse files

Added GET /screenshots/:from..:to

  • Loading branch information...
1 parent ea56734 commit 119d995bef8e96f41e91c08784e3e27d0bf7133b @tj tj committed Dec 18, 2011
Showing with 28 additions and 0 deletions.
  1. +28 −0 routes.js
View
@@ -1,6 +1,7 @@
var rasterize = require('./lib/rasterize')
, ratelimit = require('./lib/ratelimit')
+ , Batch = require('./lib/batch')
, utils = require('./lib/utils')
, path = require('path')
, join = path.join
@@ -28,6 +29,33 @@ app.get('/stats', function(req, res){
});
});
+/**
+ * GET screenshots by range.
+ */
+
+app.get('/screenshots/:from..:to', function(req, res, next){
+ var from = req.params.from
+ , to = req.params.to
+ , batch = new Batch;
+
+ db.zrange('screenshot:ids', from, to, function(err, ids){
+ if (err) return next(err);
+
+ // fetch
+ ids.forEach(function(id){
+ batch.push(function(fn){
+ db.hgetall('screenshot:' + id, fn);
+ });
+ });
+
+ // finished
+ batch.end(function(err, objs){
+ if (err) return next(err);
+ res.send(objs);
+ })
+ });
+});
+
/*
* GET screenshot.
*/

0 comments on commit 119d995

Please sign in to comment.