pastebin-worker
2022-12-5 10:46:35 Author: github.com(查看原文) 阅读量:33 收藏

This is a pastebin that can be deployed on Cloudflare workers. Try it on shz.al.

Philosophy: effortless deployment, friendly CLI usage, rich functionality.

Features:

  1. Share your paste with as short as 4 characters
  2. Customize the paste URL
  3. Update and delete your paste as you want
  4. Expire your paste after a period of time
  5. Syntax highlighting powered by PrismJS
  6. Display markdown file as HTML
  7. Customizable 302 redirection
  8. Specify mimetype

Usage

  1. You can post, update, delete your paste directly on the website (such as shz.al).

  2. It also provides a convenient HTTP API to use. See API reference for details. You can easily call API via command line (using curl or anything else).

  3. pb is bash script to make it easier to use on command line.

Limitations

  1. If deployed on Cloudflare Worker free-tier plan, the service allows at most 100,000 reads and 1000 writes, 1000 deletes per day.
  2. Due to the size limit of Cloudflare KV storage, the size of each paste should be smaller than 25 MB.

Deploy

You are free to deploy the pastebin on your own domain if you host your domain on Cloudflare.

Requirements:

  1. *nix environment with bash and basic cli programs. If you are using Windows, try cygwin, WSL or something.
  2. GNU make.
  3. node and yarn.
  4. wrangler, the official cli program to manage Cloudflare workers.

Create two KV namespaces on Cloudflare workers dashboard (one for production, one for test). Remember their IDs. If you do not need testing, simply create one.

Clone the repository and enter the directory. Login to your Cloudflare account with wrangler login. Modify entries in wrangler.toml according to your own account information (account_id, zone_id, kv_namespaces.id, kv_namespaces.preview_id are what you need to modify). Refer to Cloudflare doc on how to find out these parameters.

Modify the contents in config.json (which controls the generation of static pages): BASE_URL is the URL of your site (no trailing slash); FAVICON is the URL to the favicon you want to use on your site.

Deploy and enjoy!

$ yarn install
$ mkdir dist && make deploy

Auth

If you want a private deployment (only you can upload paste, but everyone can read the paste), add the following entry to your config.json (other configurations contained in the outmost brace):

{
  "basicAuth": {
    "enabled": true,
    "passwd": {
      "admin1": "this-is-passwd-1",
      "admin2": "this-is-passwd-2"
    }
  }
}

Now every access to PUT or POST request, and every access to the index page, requires an HTTP basic auth with the user-password pair listed above. For example:

$ curl example-pb.com
HTTP basic auth is required

$ curl [email protected]/path/to/file example-pb.com
HTTP basic auth is required

$ curl -u admin1:wrong-passwd [email protected]/path/to/file example-pb.com
Error 401: incorrect passwd for basic auth

$ curl -u admin1:this-is-passwd-1 [email protected]/path/to/file example-pb.com
{
  "url": "https://example-pb.com/YCDX",
  "suggestUrl": null,
  "admin": "https://example-pb.com/YCDX:Sij23HwbMjeZwKznY3K5trG8",
  "isPrivate": false
}

文章来源: https://github.com/y35uishere/pastebin-worker
如有侵权请联系:admin#unsafe.sh