Add simple preview interface
This commit is contained in:
parent
6cbefae12d
commit
3334abb9d8
43
index.js
43
index.js
|
@ -44,6 +44,49 @@ function attach(docker_id, output_stream) {
|
|||
}
|
||||
|
||||
router.get("/", async (ctx) => {
|
||||
ctx.body = /* HTML */ `<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<form onsubmit="formSubmit(event)">
|
||||
<label for="url_input">URL:</label>
|
||||
<input type="text" name="url" id="url_input" />
|
||||
<br />
|
||||
<label for="domains">Domeny (oddzielone przecinkami):</label>
|
||||
<input
|
||||
type="text"
|
||||
name="domains"
|
||||
id="domains"
|
||||
value="doubleclick.net,facebook.com"
|
||||
/>
|
||||
<br />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
<code><pre id="output"></pre></code>
|
||||
</body>
|
||||
<script>
|
||||
async function sleep(time) {
|
||||
return new Promise((resolve) => setTimeout(resolve, time));
|
||||
}
|
||||
async function formSubmit(e) {
|
||||
e.preventDefault();
|
||||
let response = { status: "sending first request..." };
|
||||
const url = \`/api/requests?url=\${url_input.value}&\${domains.value
|
||||
.split(",")
|
||||
.map((d) => "domains[]=" + d)
|
||||
.join("&")}\`;
|
||||
const { id } = await (await fetch(url, { method: "post" })).json();
|
||||
do {
|
||||
response = await (await fetch(\`/api/requests/\${id}\`)).json();
|
||||
console.log(response);
|
||||
output.innerHTML = JSON.stringify(response, null, " ");
|
||||
await sleep(1000);
|
||||
} while (response.status !== "finished");
|
||||
}
|
||||
</script>
|
||||
</html>`;
|
||||
});
|
||||
|
||||
router.get("/preview", async (ctx) => {
|
||||
const s = new Readable({ read() {} });
|
||||
// stream data
|
||||
ctx.response.set("content-type", "txt/html");
|
||||
|
|
Loading…
Reference in New Issue
Block a user