-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·99 lines (84 loc) · 2.53 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var express = require('express');
var serveIndex = require('serve-index');
var contentDisposition = require('content-disposition');
var mustacheExpress = require('mustache-express');
var camera = require('./camera');
var app = express();
app.engine('mhtml', mustacheExpress());
app.set('view engine', 'mhtml');
app.set('view cache', false);
app.set('views', __dirname + '/views');
app.get('/', function (req, res) {
camera.list(function (list) {
res.render('index', { list: list });
});
});
app.get('/capture', function (req, res) {
res.render('capture');
});
app.get('/api/shoot', function (req, res) {
camera.shoot(function (capture) {
if (capture.hasOwnProperty('filename'))
res.json({ success: true, filename: capture.filename, path: "/output/" + capture.filename });
else
res.json({ success: false });
});
});
app.get('/api/preview', function (req, res) {
camera.preview(function (capture) {
res.json({ success: true });
});
});
app.get('/api/zoom', function (req, res) {
camera.zoom(req.query.step, function (capture) {
res.json({ success: true });
});
});
app.get('/api/start_interval', function (req, res) {
camera.start_interval();
res.json({ success: true });
});
app.get('/api/stop_interval', function (req, res) {
camera.stop_interval();
res.json({ success: true });
});
app.get('/api/get_config', function (req, res) {
if (!req.query.name) {
res.json({ success: false, error: "No config name is provided." });
} else {
camera.get_config(req.query.name, function (value, options) {
if (value && options) {
res.json({ success: true, value: value, options: options });
} else {
res.json({ success: false });
}
});
}
});
app.get('/api/set_config', function (req, res) {
if (!req.query.name) {
res.json({ success: false, error: "No config name is provided." });
} else if (!req.query.value) {
res.json({ success: false, error: "No config value is provided." });
} else {
camera.set_config(req.query.name, req.query.value, function (value, options) {
if (value && options) {
res.json({ success: true, value: value, options: options });
} else {
res.json({ success: false });
}
});
}
});
app.use('/', express.static('static'));
app.use('/output', serveIndex('output', { 'icons': true }));
app.use('/output', express.static('output', {
'index': false,
'setHeaders': setHeaders
}));
function setHeaders(res, path) {
res.setHeader('Content-Disposition', contentDisposition(path))
}
app.listen(3000, function () {
console.log('Camera Control app is listening on port 3000 ...');
});