Add simple preview interface

This commit is contained in:
Kuba Orlik 2022-05-25 19:27:12 +02:00
parent 6cbefae12d
commit 3334abb9d8

View File

@ -44,6 +44,49 @@ function attach(docker_id, output_stream) {
} }
router.get("/", async (ctx) => { 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() {} }); const s = new Readable({ read() {} });
// stream data // stream data
ctx.response.set("content-type", "txt/html"); ctx.response.set("content-type", "txt/html");