summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpreprint/run.py7
-rw-r--r--server.js29
2 files changed, 36 insertions, 0 deletions
diff --git a/preprint/run.py b/preprint/run.py
new file mode 100755
index 0000000..eeec19c
--- /dev/null
+++ b/preprint/run.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+import subprocess
+import sys
+
+print 'Das ist preprint!!1elf'
+subprocess.call(['logger', 'would print %s' % sys.argv[1]])
diff --git a/server.js b/server.js
index e941992..46e3cda 100644
--- a/server.js
+++ b/server.js
@@ -4,10 +4,14 @@ var express = require('express');
var fs = require('fs');
var http = require('http');
var url_module = require('url');
+var child_process = require('child_process');
var MjpegProxy = require('mjpeg-proxy').MjpegProxy;
var app = express();
+app.use(express.json());
+
+var storage_dir = '/home/untersuchung/storage';
var cameras = [
{
@@ -129,5 +133,30 @@ app.get('/blackout', function(req, res) {
res.send('OK');
});
+/* receives the form from the user */
+app.post('/submit', function(req, res) {
+ var timestamp = req.body.formDate;
+ var path = storage_dir + '/' + timestamp;
+ fs.mkdirSync(path);
+
+ /* Save the image to disk */
+ /* XXX: here be dragons */
+ var image = req.body.formImage;
+ var regex = /^data:.+?\/.+?;base64,(.*?)$/;
+ var matches = image.match(regex);
+ var base_data = matches[1];
+ var buffer = new Buffer(base_data, 'base64');
+ fs.writeFileSync(path + '/snapshot.jpg', buffer);
+
+ req.body.formImage = undefined;
+ var info = JSON.stringify(req.body);
+ fs.writeFileSync(path + '/info.json', info);
+
+ child_process.spawn(__dirname + '/preprint/run.py', [path], {
+ detached: true,
+ stdio: 'inherit'
+ });
+ res.send('OK');
+});
app.listen(8080);