~kyoheiu/frssco

b8b1c58f64c094469968b37ab578319e69d4b46c — Kyohei Uto 10 months ago b1b7a03
Add /api/edit
1 files changed, 16 insertions(+), 0 deletions(-)

A routes/api/edit.ts
A routes/api/edit.ts => routes/api/edit.ts +16 -0
@@ 0,0 1,16 @@
import { Handlers } from "https://deno.land/x/fresh@1.1.5/server.ts";

export const handler: Handlers = {
  GET(req, _ctx) {
    const url = new URL(req.url);
    const query = url.searchParams.get("textarea") || "";
    try {
      Deno.writeTextFileSync("feed.txt", `\n${query}`, { append: false});
      return Response.redirect(url.origin);
    } catch (e) {
      return new Response(e, {
        status: 500,
      });
    }
  },
};