diff --git a/README.md b/README.md index 2198a45..7507c3e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Paste + This is a pastebin-like, simple file sharing application targeted to run on Cloudflare Worker. [pb.nekoul.com](http://pb.nekoul.com) is the current deployment of this project. The maximum upload file size is limited to **10 MB** and the paste will be kept for **28 days** only by default. @@ -6,6 +7,7 @@ The maximum upload file size is limited to **10 MB** and the paste will be kept Please **DO NOT** abuse this service. ## Supported features + - [x] Upload paste - [x] Download paste - [x] Delete paste @@ -15,8 +17,10 @@ Please **DO NOT** abuse this service. - [x] View paste in browsers (only for text and media file) - [ ] Expiring paste (*not support directly, see [this section](#expiring-paste)*) - [ ] Render paste code with syntax highlighting +- [x] Generate QR code for paste link ## Service architecture + This project is designed to use a S3-compatible object storage (via [aws4fetch](https://github.com/mhart/aws4fetch)) as the backend storage and [Cloudflare Worker KV](https://developers.cloudflare.com/workers/runtime-apis/kv) as index. All requests are handled by [Cloudflare Worker](https://developers.cloudflare.com/workers) with the entry point `fetch()`. @@ -24,6 +28,7 @@ It is worth noting that Cloudflare Worker is run *before* the cache. Therefore, [Cache API](https://developers.cloudflare.com/workers/runtime-apis/cache/) is used instead to interact with Cloudflare cache. ## Environment variable + |Name|Description| |-|-| |`SERVICE_URL`|The URL of the service| @@ -38,26 +43,36 @@ It is worth noting that Cloudflare Worker is run *before* the cache. Therefore, **`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `ENDPOINT` should be kept secret, i.e., [put into the encrypted store](https://developers.cloudflare.com/workers/platform/environment-variables/#adding-secrets-via-wrangler).** ## API Specification + ### GET / + Fetch the Web frontpage HTML for uploading text/file (used for browsers) ### GET /api + Fetch API specification ### GET /\ -Fetch the paste by uuid. *If the password is set, this request requires additional `x-pass` header or to use [HTTP Basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication).* + +Fetch the paste by uuid. *If the password is set, this request requires additional `x-pass` header or to +use [HTTP Basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication).* ### POST / -Create new paste. Currently, only `multipart/form-data` and raw request are supported. + +Create new paste. Currently, only `multipart/form-data` and raw request are supported. +Add `?qr=1` to enable QR code generation for paste link. #### For `multipart/form-data` request, -|Form Key|Description| + +|Form Key|Description| |-|-| |`u`|Upload content| |`pass`|Paste's password| |`read-limit`|The maximum access count| +|`qrcode`|Toggle QR code generation| #### For raw request, + |Header Key|Description| |-|-| |`content-type`|The media type (MIME) of the data and encoding| @@ -68,7 +83,9 @@ Create new paste. Currently, only `multipart/form-data` and raw request are supp The request body contains the upload content. ### GET /\/\ (Not implemented) + Fetch the paste (code) in rendered HTML with syntax highlighting +Add `?qr=1` to enable QR code generation for paste link. Currently, only the following options is supported for `option` |Option|Meaning| |-|-| @@ -79,17 +96,21 @@ Currently, only the following options is supported for `option` *The authentication requirement is as same as `GET /`.* ### DELETE /\ + Delete paste by uuid. *If the password is set, this request requires additional `x-pass` header* ### POST /\/settings (Not implemented) + Update paste setting. *If the password is set, this request requires additional `x-pass` header* ## Expiring paste + S3 object lifecycle rules and Cloudflare KV's expiring key can be used to implemented expiring paste. Reference for Amazon S3 can be found in [here](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html) , and Blackblaze B2 in [here](https://www.backblaze.com/b2/docs/lifecycle_rules.html). ## Remark + You are welcome to use my project and depoly your own service. Due to the fact that the `SERVICE_URL` is hard-coded into the `paste.html`, you may simply use `Ctrl`+`R` to replace `pb.nekoul.com` with your own service URL. diff --git a/package.json b/package.json index 9f4d92a..5372c30 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "dependencies": { "aws4fetch": "^1.0.13", "nanoid": "^3.3.4", - "js-sha256": "^0.9.0" + "js-sha256": "^0.9.0", + "dedent-js": "^1.0.1" }, "devDependencies": { "@cloudflare/workers-types": "^3.11.0", diff --git a/paste.html b/paste.html index 90e70f8..7c7da6e 100644 --- a/paste.html +++ b/paste.html @@ -19,115 +19,120 @@ - - Paste + + Paste

Paste Service

- pb.nekoul.com is a pastebin-like service hosted on Cloudflare Worker.
- This service is primarily designed for own usage and interest only.
- All data may be deleted or expired without any notification and guarantee. Please DO NOT abuse this service.
- The limit for file upload is 10 MB and the paste will be kept for 28 days only by default.
- The source code is available in my GitHub repository [here].
- This webpage is designed for upload files only. - For other operations like changing paste settings and deleting paste, please make use of the - API call with curl. + pb.nekoul.com is a pastebin-like service hosted on Cloudflare Worker.
+ This service is primarily designed for own usage and interest only.
+ All data may be deleted or expired without any notification and guarantee. Please DO NOT abuse this + service.
+ The limit for file upload is 10 MB and the paste will be kept for 28 days only by default.
+ The source code is available in my GitHub repository [here].
+ This webpage is designed for upload files only. + For other operations like changing paste settings and deleting paste, please make use of the + API call with curl.

+
-
-

Upload file

- -
-
-

Upload text

- -
-
-

Settings

- - - - -
-
- - -
-
-
- - (0 bytes) -
+

Upload file

+
+
+

Upload text

+ +
+
+

Settings

+ + + + +
+
+ + +
+
+ + +
+
+
+ + (0 bytes) +
+

[Homepage][API] diff --git a/src/index.ts b/src/index.ts index 0889a60..2c3d555 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import {AwsClient} from 'aws4fetch'; import {customAlphabet} from 'nanoid'; import {sha256} from 'js-sha256'; +import dedent from 'dedent-js'; // Constants const SERVICE_URL = 'pb.nekoul.com'; @@ -27,6 +28,7 @@ const UUID_LENGTH = 4; export interface Env { PASTE_INDEX: KVNamespace; + QRCODE: ServiceWorkerGlobalScope; AWS_ACCESS_KEY_ID: string; AWS_SECRET_ACCESS_KEY: string; ENDPOINT: string; @@ -43,18 +45,19 @@ GET /api Fetch API specification GET / Fetch the paste by uuid [x] # Currently, only the following options is supported for