Skip to content
v0lPublic

About

A Blossom/NIP96 server

Topics

Resources

Stars

32 stars

Watchers

1 watching

Forks

Latest commit

 

History

541 Commits

Folders and files

Repository files navigation

Route96

Decentralized blob storage server with Nostr integration, supporting multiple protocols and advanced media processing capabilities.

badge-light Available on StartOS

Core Features

Protocol Support

  • NIP-96 - Nostr file storage with media processing
  • Blossom Protocol - Complete BUD specification compliance:
    • BUD-01 - Blob retrieval (GET/HEAD)
    • BUD-02 - Upload, delete, list operations
    • BUD-04 - Blob mirroring from remote servers
    • BUD-05 - Media optimization endpoints
    • BUD-06 - Upload requirement validation
    • BUD-08 - NIP-94 metadata support
    • BUD-09 - Content reporting system
    • BUD-13 - Path-based blob uploads

Media Processing

  • Image & Video Compression - Automatic WebP conversion and optimization
  • Thumbnail Generation - Auto-generated thumbnails for images and videos
  • Blurhash Calculation - Progressive image loading with blur previews
  • AI Content Labeling - Automated tagging using configurable HuggingFace ViT models
  • Media Metadata - Automatic extraction of dimensions, duration, bitrate
  • Range Request Support - RFC 7233 compliant partial content delivery

Content Moderation

  • Automated Flagging - Files are automatically flagged (LabelFlagged) when AI labels match configured terms
  • User Reports - Community-driven reporting via NIP-56; flagged files get Reported state
  • Review Queue - Admin API to list all files pending review (LabelFlagged or Reported)
  • Admin Actions - Mark files as reviewed or hard-delete them directly from the queue
  • Background Labeling - Retroactively labels existing uploads that were missed at upload time

Security & Administration

  • Nostr Authentication - Cryptographic identity with kind 24242 events
  • Whitelist Support - Restrict uploads to approved public keys
  • Quota Management - Per-user storage limits with payment integration
  • Admin Dashboard - Web interface for content and user management
  • CORS Support - Full cross-origin resource sharing compliance
  • EXIF Privacy Protection - Optional rejection of images with sensitive metadata (GPS, device info)

NIP-98 HTTP auth

Admin, NIP-96 and payment endpoints use NIP-98 (kind 27235). The u tag must have the same scheme, host and port as public_url and the path of the request (a query string is ignored), and created_at must be within 60 seconds of server time whatever the expiration tag says. The request Host header is deliberately not accepted as an alternative: a client controls it, so a signed event captured by another site could be replayed here by sending that site's name as Host. If the web UI is served from an alias (www., a second domain, localhost), set public_url to the address clients use and point the UI at it with VITE_API_URL; a mismatch is rejected with x-reason: U tag does not match public_url and request path, set public_url to the address clients use.

Payment System

  • Lightning Network - Bitcoin payments via LND integration
  • Fiat Tracking - Multi-currency support (USD/EUR/GBP/JPY/etc.)
  • Flexible Billing - Usage-based pricing (storage, egress, time-based)
  • Free Quotas - Configurable free tier for new users

Analytics & Monitoring

  • Plausible Integration - Privacy-focused usage analytics
  • Comprehensive Logging - Detailed operation tracking with per-label confidence scores

API Endpoints

Blossom Protocol

  • GET /<sha256> - Retrieve blob by hash
  • HEAD /<sha256> - Check blob existence
  • PUT /<sha256> - Upload a blob using its lowercase SHA-256 path (BUD-13)
  • PUT /upload - Legacy-compatible blob upload
  • DELETE /<sha256> - Delete owned blob
  • GET /list/<pubkey> - List user's blobs
  • PUT /mirror - Mirror blob from remote URL
  • PUT /media - Upload with media optimization
  • HEAD /upload - Validate upload requirements
  • PUT /report - Submit content reports

NIP-96 Protocol

  • GET /.well-known/nostr/nip96.json - Server information
  • POST /nip96 - File upload with Nostr auth
  • DELETE /nip96/<sha256> - Delete with Nostr auth

Admin Interface

  • GET /admin/self - Current user info and quota
  • GET /admin/files - List all files (paginated, filterable by MIME type)
  • GET /admin/files/review - List files pending moderation review
  • PATCH /admin/files/review - Mark files as reviewed (batch, JSON body)
  • DELETE /admin/files/review - Ban and delete files from disk (batch, JSON body)
  • GET /admin/files/<sha256>/similar - Find visually similar images (pHash + LSH)
  • GET /admin/reports - List unreviewed user reports
  • DELETE /admin/reports - Acknowledge reports (batch, JSON body)
  • GET /admin/user/<pubkey> - User info, files, and payment history
  • DELETE /admin/user/<pubkey>/purge - Delete all files belonging to a user
  • GET /docs.md - Admin API reference (embedded Markdown)

Configuration

Route96 uses YAML configuration. See config.yaml for a complete example.

Minimal config

listen: "127.0.0.1:8000"
database: "mysql://user:pass@localhost:3306/route96"
storage_dir: "./data"
max_upload_bytes: 104857600  # 100MB
public_url: "https://your-domain.com"

Hot/cold storage

cold_storage_dir: "/mnt/hdd/route96"  # slow storage, read at startup
cold_storage_min_downloads: 50         # default 50
cold_storage_after_days: 7             # default 7

A background task moves files older than cold_storage_after_days with fewer than cold_storage_min_downloads downloads (egress bytes / size) from storage_dir to cold_storage_dir, and moves cold files back once they reach the threshold. Both thresholds can be changed from the admin config page. Files are copied, hash checked, then removed from the source, and are served from whichever tier holds them.

AI Labeling & Auto-moderation

# Directory where HuggingFace model files are cached (default: <storage_dir>/models)
models_dir: "./data/models"

# Models to run on every upload. Files are downloaded from HuggingFace on first use.
label_models:
  - hf_repo: "google/vit-base-patch16-224"
    name: "vit224"
  - hf_repo: "v0l/route96-nsfw-vit224"
    name: "nsfw"
    label_exclude:
      - "normal"   # suppress the "clean" class from the NSFW model

# Labels containing any of these terms (case-insensitive substring) will be
# automatically flagged for admin review.
label_flag_terms:
  - "nsfw"
  - "explicit"
  - "porn"
  - "sexy"
  - "hentai"

# Delete automatically instead of only flagging. Same case-insensitive substring
# match. Join terms with + to require a combination of labels ("beach+dog" needs
# a label containing each part, each at the minimum confidence).
# A hit needs a score of at least label_delete_min_confidence (default 0.8);
# weaker hits are only flagged. Reviewed files are deleted too. The hash is banned,
# so the same file cannot be uploaded again.
label_delete_terms:
  - "gore"
label_delete_min_confidence: 0.8
# Defaults to true: matches are only logged, recorded in label_deletions and flagged.
# Review them with GET /admin/label-deletions?dry_run=true, then set to false.
label_delete_dry_run: true

Models are downloaded once and cached under models_dir/<org>--<repo>/. A background task runs at startup to retroactively label any existing uploads that are missing labels.

Payment system

payments:
  free_quota_bytes: 104857600  # 100 MB free tier
  fiat: "USD"
  lnd:
    endpoint: "https://127.0.0.1:10001"
    tls: "/path/to/tls.cert"
    macaroon: "/path/to/admin.macaroon"
  cost:
    currency: "BTC"
    amount: 0.00000100
  unit: "GBSpace"
  interval:
    month: 1

Quick Start Examples

Upload a file (Blossom)

sha256=$(sha256sum image.jpg | cut -d' ' -f1)
auth_event='{"kind":24242,"tags":[["t","upload"],["x","'$sha256'"],["expiration","1234567890"]],"content":"Upload file"}'
auth_b64=$(echo $auth_event | base64 -w 0)

curl -X PUT "http://localhost:8000/$sha256" \
  -H "Authorization: Nostr $auth_b64" \
  -H "Content-Type: image/jpeg" \
  --data-binary @image.jpg

Retrieve a file

curl http://localhost:8000/abc123def456...789

Review the moderation queue

# List files pending review
curl -H "Authorization: Nostr $auth_b64" \
  http://localhost:8000/admin/files/review

# Mark a file as reviewed
curl -X PATCH -H "Authorization: Nostr $auth_b64" \
  http://localhost:8000/admin/files/<sha256>/review

# Delete a flagged file
curl -X DELETE -H "Authorization: Nostr $auth_b64" \
  http://localhost:8000/admin/files/<sha256>/review

Feature Flags

Flag Default Description
nip96 on NIP-96 protocol support
blossom on Blossom protocol support
media-compression off WebP conversion, thumbnails, media metadata
labels on AI content labeling (requires media-compression)
cuda off Run label models on GPU via CUDA (implies labels)
payments off Lightning payment integration
analytics on Plausible analytics
react-ui on Web dashboard interface
r96util on CLI utility binary for maintenance operations
# CPU labeling
cargo build --features "blossom,media-compression,labels"
# GPU labeling
cargo build --features "blossom,media-compression,cuda"

Requirements

  • Rust 1.70+
  • MySQL/MariaDB - Database storage
  • FFmpeg libraries - Media processing (media-compression / labels features)
  • Node.js - UI building (optional)

See docs/debian.md for detailed installation instructions.

Running

Docker Compose

docker compose -f docker-compose.prod.yml up

Docker

docker run --rm -it \
  -p 8000:8000 \
  -v ./config.yaml:/app/config.yaml \
  -e "RUST_LOG=info" \
  voidic/route96

The image runs as uid 10001 (user route96). The config file must be readable and storage_dir (and cold_storage_dir, if set) writable by that uid.

Upgrading from images before 17 Nov (root to uid 10001)

Images built before 17 Nov ran as root. Newer images run as uid 10001, so an install made with an old image has a config file and data directory owned by root, and the container stops at startup with a message like:

route96 cannot start as uid 10001:
  config file /app/config.yaml is not readable (owner 0:0 mode 600, process uid 10001)
  data directory /app/data is not writable (owner 0:0 mode 755, process uid 10001)

Stop the container, change the owner once on the host, then start it again.

With docker run and a host directory:

sudo chown 10001:10001 ./config.yaml
sudo chmod 640 ./config.yaml
sudo chown -R 10001:10001 ./data

With compose (docker-compose.prod.yml, named volume files and ./config.prod.yaml):

docker compose -f docker-compose.prod.yml stop app
sudo chown 10001:10001 ./config.prod.yaml
sudo chmod 640 ./config.prod.yaml
docker compose -f docker-compose.prod.yml run --rm --no-deps -u 0 --entrypoint chown app -R 10001:10001 /app/data
docker compose -f docker-compose.prod.yml up -d app

For a named volume with docker run, use docker run --rm -u 0 -v <volume>:/app/data --entrypoint chown voidic/route96 -R 10001:10001 /app/data. Do the same for cold_storage_dir and a separate models_dir if you set them.

If you cannot change the ownership, you can run the container as root again with --user 0:0 (docker run) or user: "0:0" (compose). This is an escape hatch, not a recommended setup: it gives up the protection the non-root user adds.

Manual

See docs/debian.md

About

A Blossom/NIP96 server

Topics

Resources

Stars

32 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages