matze / wastebin

wastebin is a pastebin
MIT License
250 stars 25 forks source link
axum pastebin rust self-hosted sqlite

wastebin

Rust

A minimal pastebin with a design shamelessly copied from bin.

DEMO (resets every day)

Features

Installation

Build from source

Install a Rust 2021 toolchain containing Rust 1.70 with rustup and run the server binary with

$ cargo run --release

Run pre-built binaries

You can also download pre-built, statically compiled Linux binaries. After extraction run the contained wastebin binary.

Run a Docker image

Alternatively, you can run a pre-built Docker image pushed to quxfoo/wastebin. Here is how to persist the database as state.db via the WASTEBIN_DATABASE_PATH environment variable and a bind mount to /path/for/storage:

$ docker run -e WASTEBIN_DATABASE_PATH=/data/state.db -v /path/for/storage:/data quxfoo/wastebin:latest

NOTE: The image is based on scratch which means it neither comes with a shell nor with TMPDIR being set. If database migrations fail with an extended sqlite error code 6410, pass TMPDIR pointing to a location, sqlite can write to.

Run with docker-compose

version: '3.3'
services:
  wastebin:
    environment:
      - WASTEBIN_DATABASE_PATH=/data/state.db
    ports:
      - "8088:8088"
    volumes:
      - './data:/data'
    image: 'quxfoo/wastebin:latest'

Make sure the ./data folder is writable by the user 10001.

Run with Nix

For Nix users, a flake.nix is also provided. Build and execute it directly with:

nix run 'github:matze/wastebin#wastebin'

Or install the provided wastebin package like you normally would.

Usage

Browser interface

When viewing a paste, you can use

Configuration

The following environment variables can be set to configure the server and run-time behavior:

API endpoints

POST a new paste to the / endpoint with the following JSON payload:

{
  "text": "<paste content>",
  "extension": "<file extension, optional>",
  "expires": <number of seconds from now, optional>,
  "burn_after_reading": <true/false, optional>
}

After successful insertion, you will receive a JSON response with the path to the newly created paste:

{"path":"/Ibv9Fa.rs"}

To retrieve the raw content, make a GET request on the /:id route and an accept header value that does not include text/html. If you use a client that is able to handle cookies you can delete the paste once again using the cookie in the Set-Cookie header set during redirect after creation.

In case the paste was encrypted, pass the password via the Wastebin-Password header.

Paste from neovim

Use the wastebin.nvim plugin and paste the current buffer or selection with :WastePaste.

Paste from clipboard

We can use the API POST endpoint to paste clipboard data easily from the command line using xclip, curl and jq. Define the following function in your .bashrc and you are good to go:

function paste_from_clipboard() {
    local URL=$(\
        jq -n --arg t "$(xclip -selection clipboard -o)" '{text: $t}' | \
            curl -s -H 'Content-Type: application/json' --data-binary @- https://wastebin.tld | \
            jq -r '. | "https://wastebin.tld\(.path)"')

    xdg-open $URL
}

Paste from stdin

To paste from stdin use the following function in your .bashrc:

function paste_from_stdin() {
    jq -Rns '{text: inputs}' | \
        curl  -s -H 'Content-Type: application/json' --data-binary @- https://wastebin.tld | \
        jq -r '. | "wastebin.tld\(.path)"'
}

It can be handy for creating pastes from logs or the output of commands, e.g. cat file.log | paste_from_stdin.

License

MIT