Document converter example
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
kapow route add '/format/input' - <<-'EOF'
|
||||||
|
kapow set /response/headers/Content-Type application/json
|
||||||
|
pandoc --list-input-formats \
|
||||||
|
| jq --raw-input --slurp 'split("\n") | .[0:-1]' \
|
||||||
|
| kapow set /response/body
|
||||||
|
EOF
|
||||||
|
|
||||||
|
kapow route add '/format/output' - <<-'EOF'
|
||||||
|
kapow set /response/headers/Content-Type application/json
|
||||||
|
pandoc --list-output-formats \
|
||||||
|
| jq --raw-input --slurp 'split("\n") | .[0:-1]' \
|
||||||
|
| kapow set /response/body
|
||||||
|
EOF
|
||||||
|
|
||||||
|
kapow route add -X POST --entrypoint '/bin/zsh -c' '/convert' - <<-'EOF'
|
||||||
|
kapow set /response/headers/Content-Type application/octet-stream
|
||||||
|
kapow set /response/headers/Content-Disposition "attachment; filename=$(kapow get /request/files/inputfile/filename).$(kapow get /request/form/to)"
|
||||||
|
pandoc --from=$(kapow get /request/form/from) \
|
||||||
|
--to=$(kapow get /request/form/to) \
|
||||||
|
--output=>(kapow set /response/body) \
|
||||||
|
=(kapow get /request/files/inputfile/content)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
kapow route add / - <<-'EOF'
|
||||||
|
kapow set /response/headers/Location /index.html
|
||||||
|
kapow set /response/status 301
|
||||||
|
EOF
|
||||||
|
|
||||||
|
kapow route add /index.html - <<-'EOF'
|
||||||
|
kapow set /response/headers/Content-Type text/html
|
||||||
|
kapow set /response/body < index.html
|
||||||
|
EOF
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Document Converter (pandoc) as a Service
|
||||||
|
|
||||||
|
A small web gui for [pandoc](https://pandoc.org) that allows to convert between text formats.
|
||||||
|
|
||||||
|
## How to run it
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kapow server DocumentConverter.pow
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## How to consume it
|
||||||
|
|
||||||
|
Visit http://localhost:8080/ from your web browser.
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
function populateCombo(combo, url, message) {
|
||||||
|
let dropdown = document.getElementById(combo);
|
||||||
|
dropdown.length = 0;
|
||||||
|
|
||||||
|
let defaultOption = document.createElement('option');
|
||||||
|
defaultOption.text = message;
|
||||||
|
defaultOption.name = combo;
|
||||||
|
|
||||||
|
dropdown.add(defaultOption);
|
||||||
|
dropdown.selectedIndex = 0;
|
||||||
|
|
||||||
|
fetch(url)
|
||||||
|
.then(
|
||||||
|
function(response) {
|
||||||
|
if (response.status !== 200) {
|
||||||
|
console.warn('Looks like there was a problem. Status Code: ' +
|
||||||
|
response.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Examine the text in the response
|
||||||
|
response.json().then(function(data) {
|
||||||
|
let option;
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
option = document.createElement('option');
|
||||||
|
option.text = data[i];
|
||||||
|
option.value = data[i];
|
||||||
|
dropdown.add(option);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error('Fetch Error -', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function loadFormats() {
|
||||||
|
populateCombo('from', 'format/input', 'Select an Input Format');
|
||||||
|
populateCombo('to', 'format/output', 'Select an Output Format');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="loadFormats();">
|
||||||
|
<form action="/convert" method="POST" enctype="multipart/form-data">
|
||||||
|
<select id="from" name="from"></select>
|
||||||
|
<select id="to" name="to"></select>
|
||||||
|
<input type="file" name="inputfile"></input>
|
||||||
|
<input type="submit" value="Convert!"></input>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user