diff options
author | Christian Franke <nobody@nowhere.ws> | 2014-03-19 15:28:48 +0100 |
---|---|---|
committer | untersuchung <untersuchung@nexus-flat.(none)> | 2014-03-19 15:28:48 +0100 |
commit | 47685493bc961f0186bab00b24eaf7367468af06 (patch) | |
tree | d6b5ea8ca97986e42d8a5faa587959de96032f00 | |
parent | ee89eb7fd44f22a3685b9cfac7eadcb8af0142be (diff) |
server: Save form information to storage dir
-rwxr-xr-x | preprint/run.py | 7 | ||||
-rw-r--r-- | server.js | 29 |
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]]) @@ -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); |