A paste service using Cloudflare Workers
Find a file
Joe Ma 0a57cf4053
Add QRCode shortcut to navbar (frontend)
Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
2023-12-11 20:13:51 +08:00
.idea Add button to copy paste uuid (web) 2023-03-27 14:44:28 +08:00
frontend Add QRCode shortcut to navbar (frontend) 2023-12-11 20:13:51 +08:00
src Update path to frontend static files 2023-11-19 02:50:56 +08:00
.eslintrc.json Update project dependencies version 2023-11-01 01:09:04 +08:00
.gitignore Initial commit 2022-06-01 02:11:52 +08:00
.prettierrc Update project dependencies version 2023-11-01 01:09:04 +08:00
package.json Refactor the whole project 2023-11-19 02:19:27 +08:00
paste.iml Add support to create paste from HTTP form 2022-06-02 01:31:56 +08:00
README.md Update service endpoint 2023-07-12 10:14:41 +08:00
tsconfig.json Add modal to show paste info (web) 2023-03-26 18:54:35 +08:00
web.iml Add button to copy paste uuid (web) 2023-03-27 14:44:28 +08:00
wrangler.toml Add URL redirection support 2022-10-13 01:26:26 +08:00
yarn.lock Refactor the whole project 2023-11-19 02:19:27 +08:00

Paste

This is a pastebin-like, simple file sharing application targeted to run on Cloudflare Worker.
pb.nekoid.cc 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.
All data may be deleted or expired without any notification and guarantee.
Please DO NOT abuse this service.

Supported features

  • Upload paste
  • Download paste
  • Delete paste
  • Update existing paste
  • Password protection (support HTTP Basic authentication and x-pass header)
  • Limit access times
  • View paste in browsers (only for text and media file)
  • Expiring paste (not support directly, see this section)
  • Render paste code with syntax highlighting
  • Generate QR code for paste link
  • Support URL redirection using HTTP status codes 301

Service architecture

This project is designed to use a S3-compatible object storage (via aws4fetch) as the backend storage and Cloudflare Worker KV as index. All requests are handled by Cloudflare Worker with the entry point fetch().
It is worth noting that Cloudflare Worker is run before the cache. Therefore, all requests will not be cached. Cache API is used instead to interact with Cloudflare cache.

Environment variable

Name Description
SERVICE_URL The URL of the service
PASTE_INDEX_HTML_URL The URL of the service frontpage HTML
UUID_LENGTH The length of the UUID of the paste (Default: 4)
PASTE_INDEX The Unique ID of Cloudflare KV namespace
AWS_ACCESS_KEY_ID The AWS access key
AWS_SECRET_ACCESS_KEY The AWS secret key
ENDPOINT The gateway endpoint to the S3 service

(Compatible to any S3-compatible object storage)
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and ENDPOINT should be kept secret, i.e., encrypted store .

Usage

curl, wget or other command line tools

Upload a file (Raw body) with password enabled

$ curl --data-binary @example.txt -H "x-pass: exmaple1234" "https://pb.nekoid.cc"

Upload a file (Formdata) with password enabled

$ curl -F u=@exmaple.txt -F "pass=example1234" "https://pb.nekoid.cc"

Upload command ouput as paste

$ lspci -v | curl -F u=@- 'https://pb.nekoid.cc'

Update a paste with QR code generation of paste link

$ echo "Hello, world!" | curl -F u=@- 'https://pb.nekoid.cc?qr=1'

Get paste

$ curl https://pb.nekoid.cc/uuid

Delete paste

$ curl -X DELETE https://pb.nekoid.cc/uuid

Web

Use pb.nekoid.cc to submit HTTP form, as same as curl.
This HTML form currenly only support paste upload.

API Specification

GET /

Fetch the Web frontpage HTML for uploading text/file (used for browsers)

GET /api

Fetch API specification

GET /<uuid>

Fetch the paste by uuid. If the password is set, this request requires additional x-pass header or to use HTTP Basic authentication.

POST /

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
u Upload content
pass Paste's password
read-limit The maximum access count
qrcode Toggle QR code generation
paste-type Set paste type
title File's title
json Use JSON response

For raw request,

Header Key Description
x-content-type The media type (MIME) of the data and encoding
x-title File's title
x-pass Paste's password
x-read-limit The maximum access count
x-paste-type Set paste type
x-qr Toggle QR code generation
x-json Use JSON response

The request body contains the upload content.

Paste type

Type Description
paste Normal paste content
link URL link to be redirected

GET /<uuid>/<option>

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
settings Fetch the paste information
download Download paste as attachment
raw Display paste as plain text
link Treat paste content as URL link

The authentication requirement is as same as GET /<uuid>.

DELETE /<uuid>

Delete paste by uuid. If the password is set, this request requires additional x-pass header

POST /<uuid>/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 , and Blackblaze B2 in here.

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.nekoid.cc with your own service URL.

Of course, contribute and report issues are also welcome! :D