Skip to content

Commit

Permalink
metadata & screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisonian committed Dec 6, 2015
1 parent d153892 commit a4df77c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
Empty file added .buildpacks
Empty file.
2 changes: 2 additions & 0 deletions app.json
Expand Up @@ -10,6 +10,8 @@
"env": {
"NODE_ENV": "production",
"BUILDPACK_URL": "https://github.com/lightning-viz/heroku-buildpack-nodejs",
"LD_LIBRARY_PATH": "/usr/local/lib:/usr/lib:/lib:/app/vendor/phantomjs/lib",
"PATH": "/usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin",
"LIGHTNING_USERNAME": {
"description": "Username to secure this instance with basic auth. (optional)",
"required": false
Expand Down
24 changes: 20 additions & 4 deletions app/controllers/visualization.js
Expand Up @@ -4,7 +4,8 @@ var _ = require('lodash');
var webshot = require('webshot');
var config = require('../../config/config');
var debug = require('debug')('lightning:server:controllers:visualizations');

var cache = require('../cache');
var concat = require('concat-stream');

exports.getData = function (req, res, next) {
var vizId = req.params.vid;
Expand Down Expand Up @@ -239,6 +240,14 @@ exports.screenshot = function(req, res, next) {
var host = req.headers.host;
var url = 'http://' + host + '/visualizations/' + vizId + '/iframe';

res.setHeader('Content-Type', 'image/png');

var img = cache.get('screenshot/' + vizId);
if(img) {
console.log(img);
return res.send(img);
}

var width = req.query.width || 1024;
var height = req.query.height || 768;

Expand All @@ -247,17 +256,24 @@ exports.screenshot = function(req, res, next) {
width: width,
height: height
},
renderDelay: 500
renderDelay: 500,
};

if(process.env.PHANTOM_PATH) {
opts.phantomPath = process.env.PHANTOM_PATH;
}

webshot(url, opts, function(err, renderStream) {

if(err) {
console.warn(err);
return res.status(500).send();
}

res.setHeader('Content-Type', 'image/png');
var concatStream = concat(function(screenshot) {
cache.put('screenshot/' + vizId, screenshot, 1000 * 60 * 10);
});

renderStream.pipe(res);
renderStream.pipe(concatStream);
});
}
1 change: 0 additions & 1 deletion app/models/visualizationtype.js
Expand Up @@ -2,7 +2,6 @@ var path = require('path');
var fs = require('fs-extra');
var Q = require('q');
var uuid = require('node-uuid');
var glob = require('glob');
var _ = require('lodash');
var env = process.env.NODE_ENV || 'development';
var dbConfig = require(__dirname + '/../../config/database')[env];
Expand Down
4 changes: 4 additions & 0 deletions app/views/session/visualization-public.jade
@@ -1,5 +1,9 @@
extends ../layout

block meta
meta(content="#{BASE_URL}visualizations/#{viz.id}/screenshot/?width=800&height=600", property="og:image")
meta(content="#{BASE_URL}visualizations/#{viz.id}/screenshot/?width=800&height=600", property="og:image:url")

block sidebar

block content
Expand Down
6 changes: 4 additions & 2 deletions config/database.js
Expand Up @@ -4,9 +4,11 @@ var config = require('./config');

var dbUrl = null;
if(process.env.DATABASE_URL) {
dbUrl = url.parse(process.env.DATABASE_URL);
dbUrl = url.parse(process.env.DATABASE_URL);
}

console.log(dbUrl)

module.exports = {
'development': {
database: (dbUrl) ? dbUrl.path.replace('/', '') : 'lightning-viz',
Expand All @@ -18,7 +20,7 @@ module.exports = {
'sync': {'force': true},
'storage': config.root + '/database.sqlite',
'logging': false
},
},
'test': {
database: (dbUrl) ? dbUrl.path.replace('/', '') : 'lightning-viz',
username: (dbUrl) ? (dbUrl.auth.split(':') || [false])[0] : null,
Expand Down
20 changes: 1 addition & 19 deletions config/express.js
Expand Up @@ -11,8 +11,6 @@ var serveStatic = require('serve-static');
var slashes = require('connect-slashes');
var favicon = require('serve-favicon');

var winston = require('winston');
var helpers = require('view-helpers');
var config = require('./config');
var pkg = require('../package.json');
var moment = require('moment');
Expand All @@ -36,19 +34,6 @@ module.exports = function (app, io) {
app.use(favicon(path.resolve(__dirname + '/../public/images/favicon.ico')));
app.use(serveStatic(config.root + '/public'));

// Use winston on production
var log;
if (env !== 'development') {
log = {
stream: {
write: function (message, encoding) {
winston.info(message);
}
}
};
} else {
log = { format: 'dev' };
}

// Don't log during tests
// Logging middleware
Expand Down Expand Up @@ -76,7 +61,7 @@ module.exports = function (app, io) {
app.use(cookieParser());

// bodyParser should be above methodOverride
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));


Expand Down Expand Up @@ -135,9 +120,6 @@ module.exports = function (app, io) {
}
}));

// should be declared after session and flash
app.use(helpers(pkg.name));

// adds CSRF support
if (process.env.NODE_ENV !== 'test') {
// app.use(csrf());
Expand Down
27 changes: 11 additions & 16 deletions package.json
Expand Up @@ -60,6 +60,7 @@
"colors": "~0.6.2",
"command-exists": "^0.1.0",
"compression": "^1.0.8",
"concat-stream": "^1.5.1",
"connect-slashes": "^1.2.0",
"cookie-parser": "^1.3.2",
"cookie-session": "^1.0.2",
Expand All @@ -69,9 +70,6 @@
"express": "^4.13.1",
"forever": "^0.11.1",
"fs-extra": "^0.11.1",
"glob": "^4.0.6",
"highlight.js": "^8.2.0",
"immutable": "^3.7.4",
"jade": "^1.11.0",
"knox": "^0.9.0",
"lodash": "^3.8.0",
Expand All @@ -81,30 +79,18 @@
"multiparty": "^3.3.1",
"node-uuid": "^1.4.1",
"npm": "~2.12.1",
"path": "~0.4.9",
"pg": "^4.4.3",
"pg-hstore": "^2.3.2",
"pym.js": "^0.4.1",
"q": "~1.0.1",
"randomstring": "^1.0.3",
"react": "^0.13.3",
"react-highlight": "^0.5.0",
"react-radio-group": "^2.0.2",
"react-simpletabs": "^0.6.1",
"request": "~2.36.0",
"sequelize": "^3.6.0",
"sequelize-cli": "^1.7.4",
"serve-favicon": "^2.1.6",
"serve-static": "^1.10.0",
"socket.io": "^1.3.6",
"sqlite3": "^3.1.1",
"sticky-session": "^0.1.0",
"superagent": "^0.18.2",
"title-case": "^1.1.1",
"validator": "~3.17.0",
"view-helpers": "^0.1.5",
"webshot": "^0.15.3",
"winston": "^0.7.3",
"yargs": "^1.3.3"
},
"devDependencies": {
Expand All @@ -126,6 +112,15 @@
"reactify": "^1.1.1",
"tiny-lr": "^0.1.6",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
"vinyl-source-stream": "^1.1.0",
"react": "^0.13.3",
"react-highlight": "^0.5.0",
"react-radio-group": "^2.0.2",
"react-simpletabs": "^0.6.1",
"highlight.js": "^8.2.0",
"immutable": "^3.7.4",
"superagent": "^0.18.2",
"pym.js": "^0.4.1",
"sequelize-cli": "^1.7.4"
}
}

0 comments on commit a4df77c

Please sign in to comment.