Create web UI for sending tags

Sure, why the hell not.
This commit is contained in:
Annika Backstrom 2017-04-09 21:46:18 -04:00
parent 43ad5281e3
commit 7e519c4736
4 changed files with 73 additions and 4 deletions

View File

@ -1,5 +1,71 @@
#!/bin/bash
const express = require('express');
const bodyParser = require('body-parser');
while echo 1234567890 ; do
sleep 0.2
done
const mustache = require('express');
var html = `
<!doctype html>
<html lang=en>
<head>
<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">
<style>
form { margin: 1em 0; }
</style>
</head>
<body>
<div class="pure-g" style="max-width: 768px; margin: 1em auto">
<div class="pure-u-1-1">
<h1>tag-reader-dummy</h1>
<form method="post" class="pure-form">
<input class="pure-button pure-button-primary" type="submit" name="uid" value="12121212">
</form>
<form method="post" class="pure-form">
<input class="pure-button pure-button-primary" type="submit" name="uid" value="BADC0FFEE">
</form>
<form method="post" class="pure-form">
<input type="text" name="uid" value="0123456789"> <input class="pure-button pure-button-primary" type="submit">
</form>
</div>
</div>
<script>
HTMLCollection.prototype.forEach = Array.prototype.forEach;
document.getElementsByTagName('form').forEach(function(form) {
form.onsubmit = function(e) {
e.preventDefault();
var uid = e.target.querySelector('[name=uid]').value;
console.log(uid);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8191/', true);
xhr.setRequestHeader('Content-Type', 'application\/x-www-form-urlencoded');
xhr.send('uid=' + uid);
};
});
</script>
</body>
</html>
`;
var app = express();
var server = require('http').createServer();
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function(req, res, next) {
res.send(html);
});
app.post('/', function(req, res, next) {
var uid = req.body.uid;
if (uid) {
process.stdout.write(uid);
}
res.send('ok');
});
server.on('request', app);
server.listen(8191, function () {
process.stderr.write('tag-reader-dummy listening at http://localhost:8191');
})

View File

@ -4,5 +4,6 @@
"player.js"
, "jukebox"
, "templates"
, "bin/tag-reader-dummy"
]
}

View File

@ -14,6 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.14.0",
"glob": "^7.1.1",
"morgan": "^1.7.0",

View File

@ -54,6 +54,7 @@ process.on('exit', exitHandler.bind(null));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
TagReader.on('message', tag => {
logger.debug("got tag from tagreader", { tag: tag });
MediaLibrary.find(tag);
});