Skip to content
Snippets Groups Projects
Commit d42ae5c6 authored by Jan Grewe's avatar Jan Grewe
Browse files

use webinterface to show latest photo

parent 24d937c9
Branches
No related tags found
No related merge requests found
......@@ -24,4 +24,5 @@ build/Release
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
photos/*
\ No newline at end of file
config.json
public/previews/*
\ No newline at end of file
var localFolder = "./photos";
//var username = "admin";
//var password = "admin";
var config = require('./config.json');
var pathPhotos = config.pathPhotos;
var cardAddr = config.broadcastAddr;
var pathPreviews = "./public/previews";
var itvPing = null;
var cardFound = false;
var alreadySearching = false;
var cardAddr = "192.168.0.255";
var http = require('http');
var path = require('path');
var net = require('net');
var dgram = require('dgram');
var fs = require('fs');
var gm = require('gm');
/* Express */
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var latestPhoto = require('./routes/latest');
var allPhotos = require('./routes/all');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/latest', latestPhoto);
app.use('/all', allPhotos);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
/* WiPho */
photos = new Array();
photoIndex = 0;
console.log("#########################################");
console.log("# Make sure you shoot JPEG or RAW+JPEG! #");
......@@ -24,10 +95,10 @@ function downloadPhoto(path) {
path = path.substr(5).replace(/\0/g, '');
var photo = path.split('/').pop();
var url = 'http://'+cardAddr+path;
var localFile = localFolder+'/'+photo;
var localFile = pathPhotos+'/'+photo;
var localPreview = pathPreviews+'/'+photo;
console.log("---");
console.log("Downloading "+url);
console.log('Downloading http://'+cardAddr+path);
var file = fs.createWriteStream(localFile);
......@@ -37,8 +108,24 @@ function downloadPhoto(path) {
file.on('finish', function() {
file.close();
console.log('Photo '+photo+' written to '+localFolder+'/'+photo);
console.log('Photo '+photo+' written to '+localFile);
gm(localFile).autoOrient().resize(1920, 1080).write(localPreview, function (err) {
if (!err) {
console.log('Photo resized!');
if(photos.length == 0 || photo != photos[photos.length-1].name) {
photos.push({id: photoIndex, name: photo});
photoIndex++;
}
}else{
console.log('Photo resize error: '+err);
}
console.log("---");
});
});
var options = {
......
#!/usr/bin/env node
var debug = require('debug')('foo');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
{
"pathPhotos" : "/path/to/photos/folder",
"broadcastAddr" : "192.168.0.255"
}
{
"name": "WiPho",
"version": "0.1",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.9.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"jade": "~1.6.0",
"gm": "~1.16.0"
}
}
\ No newline at end of file
This diff is collapsed.
$(document).ready(function() {
$('body').height($(window).height());
getLatest();
setInterval(function() {
getLatest();
}, 3000);
});
function getLatest() {
$.getJSON('/latest', function(data) {
if('/previews/'+data.name != $('#latest').attr('src')) {
$('#latest').attr('src', '/previews/'+data.name);
}
});
}
\ No newline at end of file
body {
margin: 0px;
padding: 0px;
}
a {
color: #00B7FF;
}
#latest {
max-width: 100%;
max-height: 100%;
}
\ No newline at end of file
var express = require('express');
var router = express.Router();
/* GET all photos. */
router.get('/', function(req, res) {
res.json(photos);
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET latest photo. */
router.get('/', function(req, res) {
res.json(photos[photos.length-1]);
});
module.exports = router;
extends layout
block content
h1= message
h2= error.status
pre #{error.stack}
extends layout
block content
//h1= title
//p Welcome to #{title}
img(id='latest' src='')
\ No newline at end of file
doctype html
html
head
title= title
script(src='/javascripts/jquery-1.11.1.min.js')
script(src='/javascripts/wipho.js')
link(rel='stylesheet', href='/stylesheets/wipho.css')
body
block content
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment