1
0
Fork 0
mirror of https://github.com/Jackzmc/PasteLite.git synced 2026-02-03 12:56:30 -06:00
A fast, simple, and lightweight tool for creating and viewing text content
  • TypeScript 65.3%
  • HTML 29%
  • Handlebars 3.7%
  • Dockerfile 2%
Find a file
2025-08-16 12:52:56 -05:00
src add LISTEN_IP env 2025-08-16 12:52:56 -05:00
static Update docs 2025-08-06 10:54:55 -05:00
views Cleanup 2025-08-06 12:24:22 -05:00
.dockerignore Add docker-compose 2025-08-06 13:04:07 -05:00
.gitignore Add docker-compose 2025-08-06 13:04:07 -05:00
docker-compose.yml add LISTEN_IP env 2025-08-16 12:52:56 -05:00
Dockerfile Add docker-compose 2025-08-06 13:04:07 -05:00
LICENSE Initial commit 2023-02-27 20:23:56 -06:00
package.json Update version 2025-08-06 13:04:28 -05:00
README.md add LISTEN_IP env 2025-08-16 12:52:56 -05:00
tsconfig.json Release 2023-02-27 20:16:57 -06:00
tsconfig.tsbuildinfo Release 2023-02-27 20:16:57 -06:00
yarn.lock Remove dotenv 2025-08-06 12:59:50 -05:00

PasteLite

Very lightweight and simple paste service. Can support any type of file configured, and can display in HTML, raw text, or JSON. Pastes can automatically expire after a set time.

Written in typescript and using Fastify & Handlebars, PasteLite is a fast, simple, and lightweight tool to just allow without registration users to paste content and retrieve it simply.

Pastes are stored using sqlite into a pastes.db file

Routes

  • POST /paste - Create a new paste with type based off content-type
    • Query Parameters:
      • expires - The time in seconds from creation for to expire, 0 if allowed to never expire
      • textOnly - Returns all information in plain text, per line to make it easier to parse without a JSON library
    • Returns:
      • JSON (default): { name, url, expires, type, deleteToken }
      • Text (?textOnly): name\ndeleteToken\nurl
  • GET /:name GET /:name.html - Returns HTML of a paste with syntax highlighting
    • Query Parameters:
      • theme - Can be set to 'light' to use a light theme
  • GET /:name/raw GET /:name.txt - Returns text/plain of the paste's content
  • GET /:name/json GET /:name.json - Returns paste's JSON if available
    • Returns:
      • 200 { name, content, expires, type }
      • 404 if paste content not JSON ($.error = PASTE_NOT_JSON)
      • 404 if paste does not exist ($.error = PASTE_NOT_FOUND)
  • GET /:name/meta GET /:name.meta.json - Returns metadata of the paste in JSON
    • Returns:
      • { name, content, expires, type }
      • 404 if paste does not exist ($.error = PASTE_NOT_FOUND)
  • DELETE /:name/:deleteToken - Deletes a paste with the given delete token (given on creation)
    • Returns:
      • 204 on success
      • 401 on incorrect/missing token
      • 404 if paste does not exist ($.error = PASTE_NOT_FOUND)

Examples

Paste a file (as plain text)

cat text.txt | curl http://localhost:8080/paste -X POST --data-binary @- -H "Content-Type: text/plain"

Paste JSON

curl -H "Content-Type: application/json" -d @data.json http://localhost:8080/paste

Paste & Get URL

#!/bin/bash
DOMAIN=http://localhost:8080
PASTE_ID=$(
    echo "test content im uploading" |
    curl -sbX POST $DOMAIN/paste?textOnly=1 -H 'Content-Type: text/plain' --data-binary @- | 
    # Returns id and delete token, only grab id
    head -1
)
echo Paste: $DOMAIN/$PASTE_ID.txt

Config

All the settings you want to change can be configured through environmental variables:

WEB_PORT = The port the server to run on
LISTEN_IP - The IP address to listen to, default 0.0.0.0
PASTE_DEFAULT_EXPIRES - The default amount of seconds a paste will expire, default is 1 day
PASTE_MAX_EXPIRES - If set, will put maximum amount of seconds that a paste can expire 
PASTE_ALLOWED_MIMES - The mime types that are allowed, by default is application/json (text/* always allowed)
PASTE_ID_ALPHABET - The characters to use for generating ids, default is '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
PASTE_ID_LENGTH - The number of characters to generate for an id, default is 12
PASTE_URL_PREFIX - If set, creating a paste will return 'url' with this being prefixed with paste name
PASTE_CLEANUP_INTERVAL - How often to check for pastes to be cleaned up in seconds. It is not the actual paste expiration. (default: 3600s)
BODY_LIMIT - Fastify's max request body size (default 1048576 (1MiB) )