dodanie tempstream

Summary: Ref T2491

Reviewers: #reviewers

Subscribers: jenkins-user

Maniphest Tasks: T2491

Differential Revision: https://hub.sealcode.org/D1174
master
kittenfromvoid 3 years ago committed by Kuba Orlik
parent 1168aa3bd0
commit 9d8ca9e751

13
package-lock.json generated

@ -14,7 +14,8 @@
"multiple-scripts-tmux": "^1.0.3",
"nodemon": "^2.0.7",
"sealious": "^0.13.38",
"stimulus": "^2.0.0"
"stimulus": "^2.0.0",
"tempstream": "^0.0.7"
},
"devDependencies": {
"@sealcode/ansi-html-stream": "^1.0.1",
@ -8662,6 +8663,11 @@
"node": ">= 6"
}
},
"node_modules/tempstream": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/tempstream/-/tempstream-0.0.7.tgz",
"integrity": "sha512-Etn/RJSwL+u7QGpk3acTXkxsJ8wgg20glZt1sQ0Zah1pPhoxqqOANjS9WrlILYfcdr8XrAgnhmk1ntN+Y2x0ew=="
},
"node_modules/term-size": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",
@ -16608,6 +16614,11 @@
}
}
},
"tempstream": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/tempstream/-/tempstream-0.0.7.tgz",
"integrity": "sha512-Etn/RJSwL+u7QGpk3acTXkxsJ8wgg20glZt1sQ0Zah1pPhoxqqOANjS9WrlILYfcdr8XrAgnhmk1ntN+Y2x0ew=="
},
"term-size": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz",

@ -25,7 +25,8 @@
"multiple-scripts-tmux": "^1.0.3",
"nodemon": "^2.0.7",
"sealious": "^0.13.38",
"stimulus": "^2.0.0"
"stimulus": "^2.0.0",
"tempstream": "^0.0.7"
},
"devDependencies": {
"@sealcode/ansi-html-stream": "^1.0.1",

@ -1,10 +1,10 @@
import { Context } from "sealious";
import { Templatable, tempstream } from "tempstream";
import { Readable } from "stream";
import { BaseContext } from "koa";
export default async function html(
_context: Context,
body: string
): Promise<string> {
return /* HTML */ `<!DOCTYPE html>
export default function html(ctx: BaseContext, body: Templatable): Readable {
ctx.set("content-type", "text/html;charset=utf-8");
return tempstream/* HTML */ ` <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />

@ -2,22 +2,24 @@ import Router from "@koa/router";
import { Context, Middlewares } from "sealious";
import html from "../html";
import { NewTask, TaskList } from "../views/tasks";
import { BaseContext } from "koa";
import { Readable } from "stream";
const router = new Router();
export async function MainView(context: Context): Promise<string> {
return await html(
context,
/* HTML */ `<title>My ToDo App</title>
export async function MainView(ctx: BaseContext): Promise<Readable> {
return html(
ctx,
/* HTML */ ` <title>My ToDo App</title>
<body>
<h1>My ToDo App</h1>
${await TaskList(context)} ${NewTask()}
${await TaskList(ctx.$context)} ${NewTask()}
</body>`
);
}
router.get("/", Middlewares.extractContext(), async (ctx) => {
ctx.body = await MainView(ctx.$context);
ctx.body = MainView(ctx);
});
export default router;

@ -6,7 +6,7 @@ import html from "../html";
const router = new Router();
router.get("/", Middlewares.extractContext(), async (ctx) => {
ctx.body = await html(ctx.$context, LoginForm());
ctx.body = html(ctx, LoginForm());
});
router.post(
@ -27,8 +27,8 @@ router.post(
ctx.redirect("/user");
} catch (e) {
ctx.status = 422;
ctx.body = await html(
ctx.$context,
ctx.body = html(
ctx,
LoginForm(ctx.$body.username as string, (e as Error).message)
);
}

@ -15,7 +15,7 @@ router.post(
done: false,
})
.save(ctx.$context);
ctx.body = await MainView(ctx.$context);
ctx.body = MainView(ctx);
}
);
@ -25,7 +25,7 @@ router.delete("/:task_id", Middlewares.extractContext(), async (ctx) => {
ctx.params.task_id
);
await task.remove(ctx.$context);
ctx.body = await MainView(ctx.$context);
ctx.body = MainView(ctx);
});
export default router;

Loading…
Cancel
Save