From 6dcf6dd967bc237e0dee321c6f7e350779a54f5d Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:30:29 +0200 Subject: [PATCH] feat: initial commit --- .gitignore | 10 ++++++++++ README.md | 23 +++++++++++++++++++++++ package.json | 13 +++++++++++++ src/index.ts | 37 +++++++++++++++++++++++++++++++++++++ tsconfig.json | 16 ++++++++++++++++ wrangler.toml | 25 +++++++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 tsconfig.json create mode 100644 wrangler.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c0be6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +node_modules +dist +.wrangler +.dev.vars + +# Change them to your taste: +package-lock.json +yarn.lock +pnpm-lock.yaml +bun.lockb \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f66725 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# featherbin + +featherbin is the fastest pastebin on the internet. it returns stuff on plaintext to experience the **true speed**. +it also has a cool name I came up with in 5 seconds and uses cheesy tech and uses hono and has only a 40-line codebase (now that's speed) +serverless btw :sunglasses: + +## usage + +send a `POST` request to `https://fb.srizan.dev/paste` with the body being the content you want to paste. the response will be plaintext, containing the url of the paste. + +## example + +```bash +$ curl -X POST https://fb.srizan.dev/paste -d "hello, world!" +asdf2 +``` + +## technologies used + +- cloudflare workers +- hono +- cloudflare kv +- typescript \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6a426e5 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "scripts": { + "dev": "wrangler dev src/index.ts", + "deploy": "wrangler deploy --minify src/index.ts" + }, + "dependencies": { + "hono": "^4.2.5" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20240403.0", + "wrangler": "^3.47.0" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..85f3b0a --- /dev/null +++ b/src/index.ts @@ -0,0 +1,37 @@ +type Bindings = { + featherbin: KVNamespace; +} + +import { Hono } from 'hono' +const app = new Hono<{ Bindings: Bindings }>() + +function randomString(length = 5) { + const charset = 'abcdefghijklmnopqrstuvwxyz0123456789' + let res = '' + for (let i = 0; i < length; i++) { + res += charset[Math.floor(Math.random() * charset.length)] + } + return res +} + +app.get('/', async (c) => { + return c.text('this is featherbin, create a paste by POSTing to /paste with the content in the body') +}) + +app.post('/paste', async (c) => { + const id = randomString() + const content = await c.req.text() + 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) + if (content === null) { + return c.text('paste not found', 404) + } + return c.text(content) +}) + +export default app diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..33a96fd --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "lib": [ + "ESNext" + ], + "types": [ + "@cloudflare/workers-types" + ], + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx" + }, +} \ No newline at end of file diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 0000000..be236cd --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,25 @@ +name = "featherbin" +compatibility_date = "2023-12-01" + +kv_namespaces = [ + { binding = "featherbin", id = "362b8cce32ee48079e0fbd201bb669a5" } +] + +# [vars] +# MY_VAR = "my-variable" + +# [[kv_namespaces]] +# binding = "MY_KV_NAMESPACE" +# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + +# [[r2_buckets]] +# binding = "MY_BUCKET" +# bucket_name = "my-bucket" + +# [[d1_databases]] +# binding = "DB" +# database_name = "my-database" +# database_id = "" + +# [ai] +# binding = "AI" \ No newline at end of file