feat: initial commit

This commit is contained in:
2024-04-21 20:30:29 +02:00
commit 6dcf6dd967
6 changed files with 124 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@@ -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

23
README.md Normal file
View File

@@ -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

13
package.json Normal file
View File

@@ -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"
}
}

37
src/index.ts Normal file
View File

@@ -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

16
tsconfig.json Normal file
View File

@@ -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"
},
}

25
wrangler.toml Normal file
View File

@@ -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"