-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (58 loc) · 1.82 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var http = require('http');
var exec = require('child_process').exec;
var express = require('express')
var app = express();
var ejs = require('ejs');
var fs = require('fs');
var photos = [];
app.engine('html', ejs.renderFile);
// Static folder with resources
app.use("/img",express.static(__dirname+"/results"));
app.use("/js",express.static(__dirname+"/js"));
app.get('/', function(req, res){
res.render('index.html');
});
app.get('/allPhotos', function(req, res){
console.log("All photos")
console.log(photos)
fs.readdir(__dirname+"/results", function(err, images){
photos = images;
return res.end(JSON.stringify(photos.reverse()));
})
});
app.get('/photo', function(req,res){
function puts(error, stdout, stderr) {
console.log(stdout);
// Make some sweeet GraphicsMagick stuff
fs.readdir(__dirname+'/pictures', function(err, images) {
if (err)
console.error(err);
if (!images)
images = [];
console.log(images.length, " number of images in folder")
var s = "gm montage -geometry 333x221 ";
for(var i = images.length-1; i > images.length-4; i--){
console.log(images[i]);
s += __dirname + "/pictures/" + images[i] + " ";
}
if (!photos)
var filename = "0.jpg";
else
var filename = photos.length + ".jpg";
photos.push(filename);
s += __dirname + "/results/"+filename;
console.log(s);
exec(s, function(err, stdout, stderr){
return res.end(filename)
});
});
}
exec("gphoto2 -I 1 -F 3 --capture-image-and-download --filename "+__dirname+"/pictures/%Y%m%d%H%M%S.%C", puts);
});
var server = app.listen(8000, function() {
function puts(error, stdout, stderr) {
console.log(stdout);
}
exec("gphoto2 --auto-detect", puts);
console.log("Listening on port %d", server.address().port);
});