lukewhrit / spacebin

🔭 spacebin: text sharing for the final frontier
https://spaceb.in
Apache License 2.0
95 stars 9 forks source link
go go-chi hastebin pastebin postgresql selfhosted spacebin

spacebin - hastebin fork focused on stability and maintainability

🚀 Spacebin

codecov GitHub license Build Go report card

Spacebin is a modern Pastebin server implemented in Go and is capable of serving notes, novels, code, or any other form of text.

Spacebin was designed to be fast and reliable, avoiding the problems of many current pastebin servers. Spacebin features JavaScript-based text highlighting, but works completely fine with JS disabled. Besides text highlighting, we have many more features in the works. It is entirely self-hostable, and available in a Docker image.

Pastebins are a type of online content storage service where users can store plain text document, e.g. program source code. For more information and the history of Pastebin see Wikipedia's article on them.

[!IMPORTANT] Try our public online version at https://spaceb.in!

Features:

Vote on future features: Image/file uploading, Account system

Looking for a URL shortener too? Try redeyes.

Table of Contents

Documentation

[!TIP] Need support? Visit our Discussions tab to get help from the community.

Self-hosting

Using Docker

# Pull and run docker image on port 80
$ sudo docker pull spacebinorg/spirit
$ sudo docker run -d -e SPIRIT_CONNECTION_URI="sqlite://database.sqlite" -p 80:9000 spacebinorg/spirit

Docker Compose

Use the following config file to host Spacebin via Docker Compose:

services:
  spacebin:
    image: spacebinorg/spirit:latest
    restart: always
    environment:
      - SPIRIT_CONNECTION_URI=postgres://spacebin:password@postgres:5432/spacebin?sslmode=disable
    ports:
      - 9000:9000
    depends_on:
      - postgres
  postgres:
    image: postgres:16.3-alpine
    restart: always
    environment:
      - POSTGRES_USER=spacebin
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=spacebin
    volumes:
      - postgres:/var/lib/postgresql/data

volumes:
  postgres:

Manually

[!IMPORTANT] Requires: Git, Go 1.22.4, GNU Makefile, and a SQLite, MySQL, or PostgreSQL server.

# Clone the Github repository
$ git clone https://github.com/lukewhrit/spacebin.git
$ cd spacebin

# Build the binary
$ make spirit

# Start Spacebin
$ SPIRIT_CONNECTION_URI="sqlite://database.sqlite" ./bin/spirit # SQLite
$ SPIRIT_CONNECTION_URI="mysql://<your instance URI>?parseTime=true" ./bin/spirit
$ SPIRIT_CONNECTION_URI="postgres://<your PostgreSQL instance URI>" ./bin/spirit # PostgreSQL

# Success! Spacebin is now available at port 9000 on your machine.

Environment Variables

Variable Name Type Default Description
SPIRIT_HOST String 0.0.0.0 Host address to listen on
SPIRIT_PORT Int 9000 HTTP port to listen on
SPIRIT_RATELIMITER String 200x5 Requests allowed per second before the user is ratelimited
SPIRIT_CONNECTION_URI String Required Database connection URI
SPIRIT_HEADLESS Bool False Enables/disables the web interface
SPIRIT_ANALYTICS String "" <script> tag for analytics (leave blank to disable)
SPIRIT_ID_LENGTH Int 8 Length for document IDs
SPIRIT_ID_TYPE "key" or "phrase" key Format of IDs: key is a random string of letters and phrase is a combination of words
SPIRIT_MAX_SIZE Int 400000 Max allowed size of a document in bytes
SPIRIT_EXPIRATION_AGE Int64 720 Amount of time to expire documents after
SPIRIT_DOCUMENTS []String [] List of any custom documents to serve

[!WARNING] Environment variables for Spacebin are prefixed with SPIRIT_. They will be updated to SPACEBIN_ in the next major version.

Database Connection URI

Spacebin supports two database formats: SQLite and Postgres

Usage

On the Web

To use Spacebin on the web, our team provides a web app. You can access the web app at spaceb.in. You must use https://spaceb.in/api to access the API routes.

A version of spacebin that is built directly from the develop branch is also available at staging.spaceb.in.

CLI

Since Spirit supports multipart/form-data uploads, it's extremely easy to use on the command line via curl. The scripts also use jq so that you can get a machine-readable version of the document's ID, instead of a lengthy JSON object.

To upload a string of text:

curl -v -F content="Hello, world!" https://spaceb.in/ | jq payload.id

To upload from a file:

curl -v -F content="$(cat helloworld.txt) https://spaceb.in/ | jq payload.id

API

There are three primary API routes to: create a document, fetch a documents text content in JSON format, and fetch a documents plain text content.

{
    "error": "",
    "payload": {
        "id": "WfwKGJfs",
        "content": "hello",
        "created_at": "2023-08-06T00:01:33.143532-04:00",
        "updated_at": "2023-08-06T00:01:33.143532-04:00"
    }
}
{
    "error": "",
    "payload": {
        "id": "WfwKGJfs",
        "content": "hello",
        "created_at": "2023-08-06T00:01:33.143532-04:00",
        "updated_at": "2023-08-06T00:01:33.143532-04:00"
    }
}

[!TIP] There are two additional non-API routes: /ping: returns a 200 OK if the service is online, and /config: returns a JSON body with the instances configuration settings.

Credits

Spacebin is a project designed and maintained by Luke Whritenour. Spacebin started out as a fork of hastebin. Although it no longer contains any code from the original, we'd like to acknowledge our roots regardless.

Spacebin itself is built using Go and various libraries (i.e. Chi, pq, Ozzo Validation, Cron, env).

A full list of code contributors is available on Github. We'd also like to thank @jackdorland for designing our logo/brand.

Vulnerabilities

The Spacebin team takes security very seriously. If you detect a vulnerability please contact us via email (hello@spaceb.in) or create a vulnerability report via Github. We request that you hold of on publishing any vulnerabilities until after they've been patched, or at least 60 days have passed since you reported it.

License

Spacebin is licensed under the Apache 2.0 license. A copy of this license can be found within the LICENSE file.