Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
|
|||
require('./main'); | |||
require('./data'); | |||
require('./palette'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,104 +1,104 @@ | |||
|
|
||
var rasterize = require('./lib/rasterize') |
|
||
, ratelimit = require('./lib/ratelimit') | var rasterize = require('../lib/rasterize') | ||
, Batch = require('./lib/batch') | , ratelimit = require('../lib/ratelimit') | ||
, utils = require('./lib/utils') | , Batch = require('../lib/batch') | ||
, path = require('path') | , utils = require('../lib/utils') | ||
, join = path.join | , path = require('path') | ||
, fs = require('fs'); | , join = path.join | ||
|
, fs = require('fs'); | ||
var dir = app.get('screenshots') |
|
||
, db = app.db; | var dir = app.get('screenshots') | ||
|
, db = app.db; | ||
/* |
|
||
* GET home page. | /* | ||
*/ | * GET home page. | ||
|
*/ | ||
app.get('/', function(req, res, next){ |
|
||
res.render('index'); | app.get('/', function(req, res, next){ | ||
}); | res.render('index'); | ||
|
}); | ||
/** |
|
||
* GET stats. | /** | ||
*/ | * GET stats. | ||
|
*/ | ||
app.get('/stats', function(req, res){ |
|
||
db.hgetall('screenshot:stats', function(err, obj){ | app.get('/stats', function(req, res){ | ||
if (err) return next(err); | db.hgetall('screenshot:stats', function(err, obj){ | ||
res.send(obj); | if (err) return next(err); | ||
}); | res.send(obj); | ||
}); | }); | ||
|
}); | ||
/** |
|
||
* GET screenshots by range. | /** | ||
*/ | * GET screenshots by range. | ||
|
*/ | ||
app.get('/screenshots/:from..:to', function(req, res, next){ |
|
||
var from = req.params.from | app.get('/screenshots/:from..:to', function(req, res, next){ | ||
, to = req.params.to | var from = req.params.from | ||
, batch = new Batch; | , to = req.params.to | ||
|
, batch = new Batch; | ||
db.zrange('screenshot:ids', from, to, function(err, ids){ |
|
||
if (err) return next(err); | db.zrange('screenshot:ids', from, to, function(err, ids){ | ||
|
if (err) return next(err); | ||
// fetch |
|
||
ids.forEach(function(id){ | // fetch | ||
batch.push(function(fn){ | ids.forEach(function(id){ | ||
db.hgetall('screenshot:' + id, fn); | batch.push(function(fn){ | ||
}); | db.hgetall('screenshot:' + id, fn); | ||
}); | }); | ||
|
}); | ||
// finished |
|
||
batch.end(function(err, objs){ | // finished | ||
if (err) return next(err); | batch.end(function(err, objs){ | ||
res.send(objs); | if (err) return next(err); | ||
}) | res.send(objs); | ||
}); | }) | ||
}); | }); | ||
|
}); | ||
/** |
|
||
* GET serve when already rasterized. | /** | ||
*/ | * GET serve when already rasterized. | ||
|
*/ | ||
app.get('/:url(*)', function(req, res, next){ |
|
||
var url = utils.url(req.params.url); | app.get('/:url(*)', function(req, res, next){ | ||
db.hget('screenshot:url:id', url, function(err, id){ | var url = utils.url(req.params.url); | ||
if (err) return next(err); | db.hget('screenshot:url:id', url, function(err, id){ | ||
if (!id) return next(); | if (err) return next(err); | ||
db.hget('screenshot:' + id, 'path', function(err, path){ | if (!id) return next(); | ||
if (err) return next(err); | db.hget('screenshot:' + id, 'path', function(err, path){ | ||
console.log('screenshot - serving rasterized %s', url); | if (err) return next(err); | ||
res.sendfile(path); | console.log('screenshot - serving rasterized %s', url); | ||
}); | res.sendfile(path); | ||
}); | }); | ||
}); | }); | ||
|
}); | ||
/* |
|
||
* GET screenshot. | /* | ||
*/ | * GET screenshot. | ||
|
*/ | ||
app.get('/:url(*)', ratelimit(60, 10), function(req, res, next){ |
|
||
var url = utils.url(req.params.url); | app.get('/:url(*)', ratelimit(60, 10), function(req, res, next){ | ||
if (!url) return res.send(400); | var url = utils.url(req.params.url); | ||
|
if (!url) return res.send(400); | ||
var id = utils.md5(url); |
|
||
|
var id = utils.md5(url); | ||
var options = { |
|
||
path: join(dir, id + '.png') | var options = { | ||
, viewportWidth: req.query.width || app.get('default viewport width') | path: join(dir, id + '.png') | ||
, viewportHeight: req.query.height || app.get('default viewport height') | , viewportWidth: req.query.width || app.get('default viewport width') | ||
}; | , viewportHeight: req.query.height || app.get('default viewport height') | ||
|
}; | ||
console.log('screenshot - rasterizing %s %dx%d' |
|
||
, url | console.log('screenshot - rasterizing %s %dx%d' | ||
, options.viewportWidth | , url | ||
, options.viewportHeight); | , options.viewportWidth | ||
|
, options.viewportHeight); | ||
rasterize(url, options, function(err){ |
|
||
if (err) return next(err); | rasterize(url, options, function(err){ | ||
console.log('screenshot - rasterized %s', url); | if (err) return next(err); | ||
app.emit('screenshot', url, options.path, id); | console.log('screenshot - rasterized %s', url); | ||
res.sendfile(options.path); | app.emit('screenshot', url, options.path, id); | ||
}); | res.sendfile(options.path); | ||
}); | }); | ||
}); |
File renamed without changes.