AniFuse subtitle catalog (sub.anikitty.moe) - encrypted at rest, self-hostable.
  • Go 67.1%
  • Shell 8%
  • CSS 7.7%
  • PowerShell 5.6%
  • HTML 5.4%
  • Other 6.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-30 10:03:14 +01:00
cmd Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
deploy Ship AniFuse Subs: Postgres + AES-GCM catalog for sub.anikitty.moe. 2026-11-30 09:40:55 +01:00
docker Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
internal Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
scripts Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
.env.example Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
.gitignore Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
docker-compose.yml Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
Dockerfile Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00
go.mod Ship AniFuse Subs: Postgres + AES-GCM catalog for sub.anikitty.moe. 2026-11-30 09:40:55 +01:00
go.sum Ship AniFuse Subs: Postgres + AES-GCM catalog for sub.anikitty.moe. 2026-11-30 09:40:55 +01:00
LICENSE Ship AniFuse Subs: Postgres + AES-GCM catalog for sub.anikitty.moe. 2026-11-30 09:40:55 +01:00
README.md Generate cryptographically random sub secrets on first create and refuse placeholders. 2026-11-30 10:03:14 +01:00

AniFuse Subs (sub.anikitty.moe)

Public subtitle catalog for AniFuse.

  • Site: https://sub.anikitty.moe
  • API: GET https://sub.anikitty.moe/v1/subs?anilistId=&episode=
  • Source of truth: this Forgejo repo — never GitHub
  • License: Apache 2.0

Monochrome glass UI. Tracks are aggregated, deduped (identical file/content collapses; at most one row per sourceId + language), stamped with age, and fetched through a one-contact-per-source TTL gate so enrichment cannot loop forever.

Secrets (random on create)

Self-hosters get unique cryptographically random secrets on first setup. Defaults like changeme are refused at ensure-time, container entrypoint, and process boot.

Secret Purpose
SUBS_ENCRYPTION_KEY AES-256-GCM sealing for episode track listings and SRT bodies (AFSEAL1:…). 32 random bytes as hex (64 chars).
POSTGRES_PASSWORD Postgres role password for compose / DATABASE_URL.

Generate (first boot)

Any one of:

./scripts/ensure-secrets.sh          # Linux / macOS / VPS
./scripts/compose-up.sh              # ensure + docker compose up -d --build
go run ./cmd/ensure-secrets          # cross-platform (crypto/rand)

Windows (PowerShell):

.\scripts\ensure-secrets.ps1
docker compose up -d --build

What it does:

  1. Creates .env from .env.example if missing.
  2. If SUBS_ENCRYPTION_KEY or POSTGRES_PASSWORD is empty / placeholder / weak, replaces it with openssl rand -hex 32 (or crypto/rand / /dev/urandom).
  3. Sets .env to mode 0600 (owner-only). Never commits .env.
  4. Re-runs are safe: existing strong secrets are left untouched.

Losing SUBS_ENCRYPTION_KEY

Sealed rows (*_sealed) become permanently unreadable. Back up .env (or SUBS_ENCRYPTION_KEY_FILE) offline before production use. There is no recovery without the key material.

Key rotation

  1. Stop writers (docker compose stop subs).
  2. Export / re-seal is not automated — treat rotation as a new vault:
    • Generate a new key (openssl rand -hex 32).
    • Drop sealed cache tables / volume or stand up a fresh Postgres volume.
    • Set SUBS_ENCRYPTION_KEY to the new value in .env (mode 0600).
    • Start services and re-fetch / re-ingest catalogs.
  3. Keep the old key offline only if you still need to decrypt a backup of the old volume.

Optional file-based key (root-owned):

sudo install -d -m 0700 /etc/anifuse-subs
openssl rand -hex 32 | sudo tee /etc/anifuse-subs/encryption.key >/dev/null
sudo chmod 0600 /etc/anifuse-subs/encryption.key
export SUBS_ENCRYPTION_KEY_FILE=/etc/anifuse-subs/encryption.key

Encryption layers

Layer What
In transit TLS at Caddy (sub.anikitty.moe). Prefer sslmode=require on DATABASE_URL when Postgres is remote.
At rest (disk) Encrypt the Postgres volume (LUKS / cloud disk encryption / host TDE).
At rest (app) AES-256-GCM sealed blobs (AFSEAL1:…) via SUBS_ENCRYPTION_KEY / _FILE.

Postgres (only primary store)

SQLite is not used. Connection string:

export DATABASE_URL='postgres://anifuse_subs:SECRET@127.0.0.1:5432/anifuse_subs?sslmode=require'

Schema is created on boot (episodes, files, fetch_gate, schema_migrations). Track JSON and file bodies live in *_sealed columns as ciphertext.

Quick start (Docker Compose)

./scripts/ensure-secrets.sh    # or compose-up.sh / ensure-secrets.ps1
docker compose up -d --build
curl -sS http://127.0.0.1:8791/health
curl -sS 'http://127.0.0.1:8791/v1/subs?anilistId=1535&episode=1'

Optional: set UPSTREAM_SUBS_ORIGIN to a legacy /api/subs/{id}/{ep} host. Each episode and file id is contacted at most once per 30 minutes (memory + Postgres fetch_gate).

Run from source

go mod tidy
go run ./cmd/ensure-secrets
set -a && . ./.env && set +a
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5433/${POSTGRES_DB}?sslmode=disable"
go run ./cmd/server

API shape

GET /v1/subs?anilistId=1535&episode=1
{
  "anilistId": 1535,
  "episode": 1,
  "title": "Death Note",
  "cached": true,
  "resolvedAtMs": 1730000000000,
  "tracks": [
    {
      "id": "anikoto|en|…",
      "sourceId": "anikoto",
      "source": "Anikoto",
      "language": "en",
      "label": "🇬🇧 English",
      "url": "https://sub.anikitty.moe/v1/file?id=…",
      "mimeType": "application/x-subrip",
      "ageMs": 120000,
      "ageLabel": "2m ago",
      "resolvedAtMs": 1730000000000
    }
  ]
}

Also:

Method Path Notes
GET /v1/file?id={64hex} Sealed SRT download
GET /v1/library Local sealed shows
GET /api/subs/{id}/{ep} Legacy SoftReplace shape
GET /health Liveness

Caddy + DNS (sub.anikitty.moe)

  1. DNS A/AAAA sub.anikitty.moe → VPS (143.246.203.212).
  2. Append deploy/Caddyfile.snippet to the host Caddyfile.
  3. systemctl reload caddy (or your Caddy unit).
  4. Run compose / binary on 127.0.0.1:8791 (after ensure-secrets).

Android app wiring

AniFuse (anifuse-android) points SubtitleLibrary at:

https://sub.anikitty.moe

and prefers GET /v1/subs?anilistId=&episode=. Disk/memory caption cache remains the offline SoftReplace fallback when the host is unreachable.

No encryption keys ship in the Android APK. Clients only talk HTTPS to the public API.

To point a fork at your self-host, change SUBTITLE_LIBRARY_ORIGIN in the Android client (or set a future build-time override) to your public HTTPS base.

Security notes

  • Do not commit .env, encryption keys, Postgres passwords, or app.ini secrets.
  • Empty / changeme / placeholder secrets are rejected — the API will not start.
  • Bind Postgres to localhost (or private network) unless TLS + strong auth are configured.
  • The service stores captions operators choose to cache; it does not scrape from the Android APK.

Forgejo

https://git.anikitty.moe/anifuse/anifuse-subs

Public by default. origin must stay on Forgejo — never mirror to GitHub.