| author | |
| committer | |
| log | 3054df53b55f49b1421c222591bbd4d7f7e935c0 |
| tree | 35d653cf56fc51913b7d574e4cba9c73d5f575d3 |
| parent | 123f64dc0198ef576cae7e75bc02f2742c527d93 |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 29 insertions(+), 0 deletions(-)
framework/lib/path.ts+4| ... | @@ -193,6 +193,10 @@ export class Path { | ... | @@ -193,6 +193,10 @@ export class Path { |
| 193 | await fs.writeFile(this.raw, JSON.stringify(json)); | 193 | await fs.writeFile(this.raw, JSON.stringify(json)); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | async writeMkdir(text: string) { | ||
| 197 | await fs.writeMkdir(this.raw, text); | ||
| 198 | } | ||
| 199 | |||
| 196 | static sep = path.sep; | 200 | static sep = path.sep; |
| 197 | 201 | ||
| 198 | [Symbol.for("nodejs.util.inspect.custom")]( | 202 | [Symbol.for("nodejs.util.inspect.custom")]( |
src/backend-extra.ts created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | export const app = new Hono(); | ||
| 2 | |||
| 3 | app.get("/extra/secret-message", async (c) => { | ||
| 4 | const { key } = c.req.query(); | ||
| 5 | if (!key || !key.match(/^[a-z0-9]+$/)) { | ||
| 6 | return c.text("400 bad request", { status: 400 }); | ||
| 7 | } | ||
| 8 | const text = await Path.resolve(".clover/secret-message", key) | ||
| 9 | .readIfExists("utf-8"); | ||
| 10 | if (text) return c.text(text); | ||
| 11 | return c.text("401 not authorized", { status: 401 }); | ||
| 12 | }); | ||
| 13 | app.post("/admin/extra/secret-message", async (c) => { | ||
| 14 | const key = c.req.query("key"); | ||
| 15 | if (!key || !key.match(/^[a-z0-9]$/)) { | ||
| 16 | return c.text("400 bad request", { status: 400 }); | ||
| 17 | } | ||
| 18 | await Path.resolve(".clover/secret-message", key) | ||
| 19 | .writeMkdir(await c.req.text()); | ||
| 20 | return c.text("ok", { status: 200 }); | ||
| 21 | }); | ||
| 22 | |||
| 23 | import { Path } from "#sitegen/path"; | ||
| 24 | import { Hono } from "hono"; | ||
src/backend.ts+1| ... | @@ -12,6 +12,7 @@ app.use(admin.middleware); | ... | @@ -12,6 +12,7 @@ app.use(admin.middleware); |
| 12 | app.route("", require("./q+a/backend.ts").app); | 12 | app.route("", require("./q+a/backend.ts").app); |
| 13 | app.route("", require("./file-viewer/backend.tsx").app); | 13 | app.route("", require("./file-viewer/backend.tsx").app); |
| 14 | app.route("", require("./friend-auth.ts").app); | 14 | app.route("", require("./friend-auth.ts").app); |
| 15 | app.route("", require("./backend-extra.ts").app); | ||
| 15 | 16 | ||
| 16 | // Asset middleware has least precedence | 17 | // Asset middleware has least precedence |
| 17 | app.use(assets.middleware); | 18 | app.use(assets.middleware); |