From e0de6ec34290b72a137daced57546ff529579207 Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:46:39 +0200 Subject: [PATCH] fix some other stuff --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 12a4d11..d9c9a34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ function randomString(length = 5) { } app.get('/', async (c) => { - return c.text('this is featherbin, create a paste by POSTing to /paste with the content in the body or as a query parameter called "data"\nhttps://github.com/SrIzan10/featherbin') + return c.text('this is featherbin, create a paste by POSTing or GETting the /paste route with the content in the body or as a query parameter called "data"\nhttps://github.com/SrIzan10/featherbin') }) app.post('/paste', async (c) => { @@ -28,6 +28,16 @@ app.post('/paste', async (c) => { return c.json({ id }) }) +app.get('/paste', async (c) => { + const id = randomString() + const content = await c.req.text() || c.req.query('data') + if (!content) { + return c.text('no content provided', 400) + } + await c.env.featherbin.put(id, content) + return c.json({ id }) +}) + app.get('/:id', async (c) => { const id = c.req.param('id') const content = await c.env.featherbin.get(id)