diff --git a/API.md b/API.md new file mode 100644 index 0000000..2950f44 --- /dev/null +++ b/API.md @@ -0,0 +1,62 @@ +# API + +## Create a paste + +### Request + +**Method:** `POST /api/paste` + +#### Body + +| Name | Type | Description | Required | +| ---- | ---- | ----------- | -------- | +| `content` | `string` | Paste content. If encrypted, must be encoded into a string (preferably Base64). | Yes | +| `config` | `object` | Configuration for the paste | No | +| `passwordProtected` | `boolean` | Whether the paste is password protected. | No | +| `initVector` | `string` | Initialization vector for AES encryption. Max length: 64. | No | + +**Config Object:** + +| Name | Type | Description | Required | +| ---- | ---- | ----------- | -------- | +| `language` | `string` | Programming language of the paste. Default: `plaintext`. | No | +| `encrypted` | `boolean` | Whether the paste is encrypted. Default: `false`. | No | +| `expiresAfter` | `number` | Time in seconds until the paste expires. | No | +| `burnAfterRead` | `boolean` | Whether the paste is deleted after reading. | No | + +### Examples + +```json +{ + "content": "i0n3PW6qDUhDaTrzoKg+/ip4qQwu+iq8/fWDVg==", + "config": { + "language": "plaintext", + "encrypted": true, + "expiresAfter": 3600, + "burnAfterRead": false + }, + "passwordProtected": false, + "initVector": "27DIWK00yDiGx001" +} +``` + +```json +{ + "content": "Hello World!", + "config": { + "language": "plaintext" + } +} +``` + +## Get a paste + +### Request + +**Method:** `GET /api/paste` + +#### Query Parameters + +| Name | Type | Description | Required | +| ---- | ---- | ----------- | -------- | +| `key` | `string` | Paste key. | Yes | diff --git a/README.md b/README.md index f97d553..62dea3c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,12 @@ Well, cause no pastebin I could find had ALL of the following features: - API support to create and get pastes from command line. - View raw pastes. Normally, encrypted pastebins do not have this. With this site, you can either get the Base64-encoded encrypted paste, or decrypt it on the server side (even with the password) and get the raw paste. - Keyboard shortcuts! - - And ofcourse, being fully open-source and easily self-hostable. + - And of course, being fully open-source and easily self-hostable. + - **It can even be run on edge servers and in serverless environments!** + + ## API Documentation + +See [API.md](API.md). ## How to use @@ -34,3 +39,9 @@ yarn dev docker build -t yabin:latest . docker run --env-file .env -it -p 3000:3000 yabin:latest ``` + +#### In a serverless environment (Cloudflare Workers, Netlify, Vercel, etc.) + +I have not yet tested this, but this is made with SvelteKit. Please take a look at the [SvelteKit documentation](https://kit.svelte.dev/docs/adapters) for more information. If there are any issues, please open an issue, and I will put up a proper guide on how to deploy on such environmments. + +**Right now, it is using PostgreSQL (cause I had a server lying around). However, it can be run using any SQL DB such as SQLite or MySQL. To use other backends, please update the provider in [schema.prisma](src/lib/server/prisma/schema.prisma)** \ No newline at end of file diff --git a/package.json b/package.json index fbfe96c..f8574e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yabin", - "version": "0.0.1", + "version": "1.0.0", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/app.html b/src/app.html index 0e86b82..113f6ff 100644 --- a/src/app.html +++ b/src/app.html @@ -7,7 +7,7 @@ - + YABin %sveltekit.head% diff --git a/src/lib/types.ts b/src/lib/types.ts index 778ad4f..0bcd6ed 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,14 +1,14 @@ export interface PasteConfig { - language: string; - encrypted: boolean; - expiresAfter: number; - burnAfterRead: boolean; + language?: string; + encrypted?: boolean; + expiresAfter?: number; + burnAfterRead?: boolean; } export interface Paste { content: string; - config: PasteConfig; - passwordProtected: boolean; + config?: PasteConfig; + passwordProtected?: boolean; initVector?: string; } diff --git a/src/routes/api/paste/+server.ts b/src/routes/api/paste/+server.ts index c2bfc12..bbb83fc 100644 --- a/src/routes/api/paste/+server.ts +++ b/src/routes/api/paste/+server.ts @@ -53,12 +53,12 @@ export const POST: RequestHandler = async ({ request }) => { data: { key, content, - language: config.language, - encrypted: config.encrypted, + language: config?.language ?? 'plaintext', + encrypted: config?.encrypted ?? false, passwordProtected, - expiresCount: config.burnAfterRead ? 2 : null, + expiresCount: config?.burnAfterRead ? 2 : null, initVector, - expiresAt: config.expiresAfter ? new Date(Date.now() + config.expiresAfter * 1000) : null + expiresAt: config?.expiresAfter ? new Date(Date.now() + config.expiresAfter * 1000) : null } }); diff --git a/src/routes/info/+page.svelte b/src/routes/info/+page.svelte index bb62963..3f674ac 100644 --- a/src/routes/info/+page.svelte +++ b/src/routes/info/+page.svelte @@ -88,17 +88,25 @@ href="https://github.com/Yureien/YABin">open-source and easily self-hostable. +
  • It can even be run in serverless environments!
  • + +

    + The API documentation is available here. +

    Support the development

    -

    +

    If you really like this project, I'd love it if you Buy Me a Coffee at ko-fi.com me on GitHub.

    -

    - Soon, after the development is mostly complete, I will be running managed servers on a - custom and short domain. You can also support me by subscribing to a monthly service, and - you get your own pastebin, with your custom styles, colours, text and more! +

    + Soon, I will be running managed servers on a custom and short domain. You can support me by + subscribing to a monthly service, and you get your own pastebin, with your custom styles, + colours, text and more! If you are interested, please send me an email at contact@sohamsen.me, and I will get back to you as soon as possible.

    diff --git a/static/yabin-logo.ico b/static/yabin-logo.ico new file mode 100644 index 0000000..34e9a7a Binary files /dev/null and b/static/yabin-logo.ico differ diff --git a/static/yabin-logo.svg b/static/yabin-logo.svg new file mode 100644 index 0000000..c3ec13f --- /dev/null +++ b/static/yabin-logo.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file