No description
  • Rust 69.1%
  • Svelte 15.4%
  • TypeScript 13.5%
  • JavaScript 0.7%
  • Shell 0.5%
  • Other 0.7%
Find a file
west eec771957b
All checks were successful
CI / ui (push) Successful in 1m47s
CI / rust (push) Successful in 5m31s
CI / e2e (push) Successful in 5m31s
CI / release (push) Successful in 3m16s
fix: Fix/enhance bsky poster
- Update the modal to not include n/N post footers
- Update the modal to support crediting other people included in the
  piece
2026-11-24 17:18:25 -05:00
.forgejo/workflows ai,feat: CI reads non-sensitive settings as variables, runbook for loading migrated data 2026-11-19 19:06:07 -07:00
.githooks fix: correct precommit hook to ensure empty DB prebuild target 2026-11-19 22:06:10 -07:00
.sqlx fix: Fix/enhance bsky poster 2026-11-24 17:18:25 -05:00
ci ai,fix: CI image takes MinIO from the Silo fork, runner mounts the podman socket by host path 2026-11-19 19:18:00 -07:00
migrations fix: Fix/enhance bsky poster 2026-11-24 17:18:25 -05:00
src fix: Fix/enhance bsky poster 2026-11-24 17:18:25 -05:00
tests fix: Fix/enhance bsky poster 2026-11-24 17:18:25 -05:00
ui fix: Fix/enhance bsky poster 2026-11-24 17:18:25 -05:00
.dockerignore ai,feat: Prep for saltlick deployment 2026-11-19 13:05:33 -07:00
.gitignore ai,feat: Prep for saltlick deployment 2026-11-19 13:05:33 -07:00
build.rs (fix): Prevent SVGs from being uploaded 2026-09-13 18:16:16 -06:00
Cargo.lock ai,feat: alt text, tags, stats, post records and posting to Bluesky 2026-11-18 22:16:22 -07:00
Cargo.toml ai,feat: alt text, tags, stats, post records and posting to Bluesky 2026-11-18 22:16:22 -07:00
DEPLOYMENT-NOTES.md ai,fix: CI image takes MinIO from the Silo fork, runner mounts the podman socket by host path 2026-11-19 19:18:00 -07:00
DEPLOYMENT.md ai,fix: CI image takes MinIO from the Silo fork, runner mounts the podman socket by host path 2026-11-19 19:18:00 -07:00
Dockerfile ai,feat: Prep for saltlick deployment 2026-11-19 13:05:33 -07:00
justfile ai,feat: improved uploads & ui, setting hero image in admin page, 2026-11-18 20:59:42 -07:00
README.md ai,feat: Prep for saltlick deployment 2026-11-19 13:05:33 -07:00
todo.md ai,feat: Prep for saltlick deployment 2026-11-19 13:05:33 -07:00

Environment Variables

Loaded from the process environment, falling back to a .env file in the working directory if one is present.

Required

The application exits at startup if any of these is unset.

Variable Type Description
S3_ENDPOINT URL Address of the S3 instance. Must be reachable by anyone viewing the UI, or presigned URLs will not resolve.
S3_BUCKET string Bucket name. Checked with HeadBucket at startup, so an unreachable or missing bucket fails fast.
S3_ACCESS_KEY string S3 access key.
S3_SECRET_KEY secret string S3 secret key.
SESSION_PRIVATE_KEY base64 string Signing and encryption key for session cookies. Must decode to at least 64 bytes — generate with openssl rand -base64 64.
STAG_CLIENT_ID string OAuth client id issued by stag. Also the expected aud on identity tokens.
STAG_CLIENT_SECRET secret string OAuth client secret. Also the HS256 key identity tokens are verified against.

Required only on first run

Read only when the database holds no root administrator, so they are needed on an empty database and ignored on every later start. Leaving them set is harmless.

Variable Type Description
AUTH_ROOT_ADMINISTRATOR_USER_STAG_ID i64 The sub of the stag identity that becomes the root administrator. Startup fails if it will not parse.
AUTH_ROOT_ADMINISTRATOR_USER_EMAIL string Email for the root administrator record.
AUTH_ROOT_ADMINISTRATOR_USER_DISPLAY string Display name. Optional even on first run — defaults to the email.

Optional

Variable Type Default Description
DATABASE_URL SQLite URL sqlite://<PATH TO FILE>. The file is created if missing; WAL and foreign keys are enabled on connect. Defaults to sqlite://deers-io.db
BIND_ADDRESS socket address 127.0.0.1:5000 Address the server listens on. Use 0.0.0.0:<port> to accept traffic from outside the host.
SECURE_COOKIES true | false true Sets the Secure flag on session cookies. Only turn it off for local HTTP development — browsers drop secure cookies over plain HTTP.
TRUST_PROXY_HEADERS true | false false Whether to believe X-Real-IP when rate limiting. Enable only behind a proxy that sets it; otherwise a client can forge a fresh rate-limit bucket per request.
CORS_ALLOWED_ORIGINS comma-separated origins unset e.g. https://deers.io,https://www.deers.io. When unset the CORS layer is not installed at all, so browsers apply same-origin rules.
STAG_API_URL URL https://stag.deers.io/api/oauth/authorize Where authorization codes are exchanged. Only the browser tests change this, to point at a stand-in for stag.
BACKUP_INTERVAL_HOURS integer 24 How often the database is backed up to the bucket. 0 turns backups off.
BACKUP_RETENTION integer 14 How many backups to keep; older ones are deleted after each new one.
TRANSCODE_THREADS integer half the CPU cores Threads the video encoder may use, so a transcode leaves cores free for serving requests.
BLUESKY_SERVICE_URL URL https://bsky.social The AT Protocol service posts are sent to. Change it for a self-hosted PDS; the browser tests point it at a stand-in.
RATE_LIMIT_BURST_SIZE integer 120 Requests one client may make in a burst before being limited; it refills at 10 a second. The browser tests raise it.
LOG_FORMAT json | unset unset json writes one JSON object per log line, for Loki or any other log shipper. Anything else keeps the human-readable format.
RUST_LOG tracing filter warn,deers_io=info,tower_http=info Standard EnvFilter syntax. Avoid trace in production — the HTTP client logs request bodies at that level, which would include the stag client secret.

UI

The SvelteKit app in ui/ reads its own environment, from ui/.env in development.

Variable Type Default Description
STAG_CLIENT_ID string required The same client id the server uses. Read at build time.
PUBLIC_API_PATH path required Path the browser uses to reach the API, e.g. /api. Read at build time.
API_URL URL required Where the UI's server reaches the API directly, e.g. http://localhost:5050.
STAG_REDIRECT_URI URL <request origin>/auth The redirect URI sent to stag when signing in. Set it in production to the public address registered with stag, e.g. https://deers.io/auth; behind a proxy the request origin is not reliable.

Notes on parsing

  • SECURE_COOKIES and TRUST_PROXY_HEADERS accept only the exact strings true and false. Any other value is ignored and the default applies, so a typo such as TRUE or 1 fails silently and leaves the safer setting in place.
  • CORS_ALLOWED_ORIGINS panics at startup on a value that is not a valid header, rather than skipping it.
  • SESSION_PRIVATE_KEY panics at startup if it decodes to fewer than 64 bytes.
  • Changing SESSION_PRIVATE_KEY invalidates every existing session.

Monitoring

Route Purpose
GET /ping Liveness. Answers "pong" without touching the database or the bucket.
GET /health Readiness. Runs a query and a HeadBucket; 200 with {"status":"ok",...} when both pass, 503 naming the failing dependency otherwise.
GET /metrics Prometheus text format: request counts and durations by method, route pattern and status, plus gauges for the generation queue, the bucket ledger, commissions, assets and bytes by kind, and the time of the newest database backup.

/metrics is unauthenticated. It carries no personal data, but it should not be public: block it at the reverse proxy and scrape it from inside the network.

Backups

The database is backed up to the same bucket, under backup/, by a background task: a consistent snapshot (VACUUM INTO) uploaded as backup/deers-io-<UTC timestamp>.db. A backup is taken when the newest one is older than BACKUP_INTERVAL_HOURS, checked every fifteen minutes, so restarts neither skip nor repeat one. The newest BACKUP_RETENTION are kept.

To restore, stop the server, download a backup and put it where DATABASE_URL points. The files in the bucket are not part of the backup: they already live there, so protect them with bucket versioning or replication on the MinIO side.

deers_io_backup_last_success_timestamp_seconds on /metrics is the time of the newest backup, for alerting when one is overdue.

Accounts

Every account in this application is a full administrator. There are no roles: any authenticated user can create, edit, and delete every commission, person, and character, and can invite further users who are also full administrators. Invites cannot currently be revoked and users cannot be removed, so only invite people you would trust with direct access to the database.

The root administrator is the account seeded on first run. It is marked by users.is_root_administrator, and the schema permits exactly one such row.

Assets

Every asset has one kind, shared by all of its variants, and a role.

Kind Accepted uploads Generated in the background Shown as
image JPEG, PNG, WebP, GIF, TIFF Resized ladder and an Open Graph card. Animated GIF/WebP/APNG get the card only, so the original keeps playing Responsive image
video Anything FFmpeg can decode H.264/AAC MP4 renditions at 1080p, 720p and 480p, never upscaled Player with a quality picker
document PDF, Markdown, plain text, DOCX, RTF DOCX and RTF are converted to a PDF with selectable text PDF viewer, or rendered Markdown/text
model3d .blend, .fbx, .glb FBX is converted to a GLB preview 3D viewer when a GLB exists, otherwise a download

Blender files cannot be converted on the server. Attach a .glb export to the same asset, at upload or later from the edit form, to get an in-browser preview.

The role is content or poster. A commission has at most one poster, always an image; it is what galleries, link previews and the video player show.

  • A commission with at least one uploaded image always has a poster: the image marked as one, or the first image when none is marked.
  • A commission with no image gets a poster generated from the first frame of a video or the first page of a PDF. Uploading an image later replaces it.
  • An uploaded poster is also one of the commission's files. Marking it cover only in the form keeps it as the cover but leaves it out of the files list. A generated poster is always cover only.

Videos shot rotated are stored upright: the rotation flag is applied to the renditions and the poster frame.

Generation

Variants, previews and posters are made by a long-lived background task inside the server, alongside the bucket reaper. It checks its queue every five seconds and works through one file at a time.

  • A run interrupted by a crash or restart is picked up by the next sweep and counts as a failed attempt.
  • After five failed attempts a file is marked failed and left alone, with the reason recorded. Admin → Generation lists everything queued or failed and can retry a failed file.
  • A video that is already an upright H.264/AAC MP4 is not re-encoded at its own size; the original is served as the top quality and only smaller renditions are made.

Uploads

Files do not pass through the server on their way in. The browser sends each one straight to the bucket in parts, a few files and a few parts at a time, and the commission form shows a progress bar per file and one for everything.

  1. POST /uploads registers a file and returns a presigned URL for each 16 MB part. Every upload lands under the ingest/ prefix, never in asset/ or invoice/ directly.
  2. The browser PUTs the parts to those URLs and reports back with POST /uploads/{id}/complete, which assembles the file and checks its size.
  3. Saving the commission names each new file by its upload id. The server then reads the file from ingest/ to sniff, probe and checksum it exactly as before, has the bucket copy it to its checksum key (the bytes are not sent a second time), and queues the ingest/ copy for deletion.

Nothing is left behind when a save never happens:

  • Removing a file from the form, or leaving the form, cancels its upload.
  • A save that is rejected keeps the uploads, so fixing the problem and saving again does not mean uploading again.
  • An upload still unclaimed after 24 hours is aborted and deleted by a background sweep, whether or not it ever finished.

The bucket must accept cross-origin PUTs from the site and expose the ETag response header; MinIO does both by default. S3_ENDPOINT therefore has to be reachable from browsers, as it already did for invoice downloads. As a second line of defence it is worth giving the bucket a lifecycle rule that aborts incomplete multipart uploads after a few days.

The older way of sending files as parts of the multipart request to /commissions still works, and is what the migration tool and the API tests use.

Home page image

Admin → Home page image picks the image shown on the home page from any received commission. Only an uploaded image that is listed among a commission's files can be chosen: not a generated poster, and not one marked cover only. The home page links the image to its commission and uses its Open Graph card for link previews. If the asset is later deleted the setting clears itself, and an archived commission's image is hidden from anonymous visitors.

Alt text

Image and video assets need alt text; the commission form and the API both refuse one without it. It becomes the image's alt and the video's accessible name, and a generated poster inherits the alt text of the asset it was made from. Documents and models are described by their name.

Tags

A commission can carry any number of tags. They are public, always lower case, and may use letters, numbers, spaces, hyphens and apostrophes. Each tag on a commission links to the gallery filtered by it, and /art?tags=deer,snow shows only works that carry every tag listed.

Admin → Tag alternates maps a synonym to the real tag (canine → dog). Typing an alternate anywhere stores the real tag instead. Making an existing tag an alternate moves its commissions onto the real tag.

Prices in USD

Every commission keeps a USD value alongside its price so totals and averages can be compared. For a USD price it is the price itself; for any other currency the form asks for the USD value at the time of payment.

Stats

Admin → Stats shows commissions started and received in the last year, how many are in progress, the average delivery time (start to received, received works only), the average price and total spent in USD, spending by currency, and a year-long activity heatmap each for commissioning and receiving. When signed in, an artist's page shows their piece count, average turnaround, average price and total spent.

Posting elsewhere

A commission page (signed in) lists where the work has been posted. A post made by hand is recorded with its platform, one of the social types, and its link.

Post to Bluesky opens a composer: choose up to four still images and their order, edit each one's alt text, and write the post. The text starts with the title, a credit for each artist and the commission's tags as hashtags. An artist with a Bluesky social is mentioned by handle; otherwise another of their socials can be chosen (By: @/name on Platform), or just their name. If any chosen image is marked sensitive the post must be labelled suggestive or adult before it can be sent; otherwise it goes out unlabelled. A reply linking back to the commission page is added to the thread, and the post is recorded on the commission.

The account is set in Admin → Bluesky with a handle and an app password; a personal account works, no bot account is needed. The app password is encrypted with a key derived from SESSION_PRIVATE_KEY before it is stored, is never returned by the API, and can be replaced or removed there. Changing SESSION_PRIVATE_KEY means entering it again.

References between commissions

A description can point at another commission by number: [[#12]]. When the commission is read, each reference to a commission that exists is returned in references with its title, and the UI shows it as a link labelled with that title (or its catalogue number, if it has not been received yet). A reference to an unknown commission is left as written. A reference to an archived commission is resolved only for signed-in users; everyone else sees the word ARCHIVED in its place, with no title and no link.

Asset files are public, except those of an archived commission, which are served only to signed-in users and are never cacheable.

Development

Native libraries

Processing uploads links against three native libraries, so they must be installed wherever the server is built and run:

Library Used for macOS Debian/Ubuntu
FFmpeg (libav*, built with libx264) Probing videos, transcoding the MP4 rendition ladder, poster frames brew install ffmpeg libavcodec-dev libavformat-dev libavfilter-dev libavutil-dev libswscale-dev libswresample-dev
Assimp Converting FBX models to a GLB preview brew install assimp libassimp-dev
pkg-config and libclang Locating the above and generating their bindings at build time brew install pkgconf pkg-config libclang-dev

PDF rendering, and the DOCX/RTF to PDF conversion, are pure Rust and need nothing installed. The conversion embeds its own serif font and falls back to fonts installed on the host for scripts that font does not cover.

Git hooks

Register the git hooks after cloning:

git config core.hooksPath .githooks

The pre-commit hook runs cargo check and cargo clippy, and verifies that the .sqlx offline query cache matches the queries being committed. A stale cache builds fine for anyone holding a migrated dev.db and fails for everyone else, CI and fresh clones included. Installing sqlx-cli is required for the check:

cargo install sqlx-cli

Deployment and CI

DEPLOYMENT.md covers the container images, the Forgejo pipeline (lint, tests, coverage gate, versioned releases), and the dokku, nginx and MinIO setup.

Testing

Run everything with cargo test. No database setup is needed: #[sqlx::test] applies migrations/ to a throwaway database (under target/sqlx/) for every test, and hands it over as a SqlitePool argument. No environment variables are needed either — integration tests build the router from fixtures rather than from the environment, and never reach S3 or stag.

Browser tests

just e2e builds the server and runs the Playwright suite in ui/e2e headlessly against the real stack: the server on a throwaway SQLite database, the UI, a real bucket, and a small stand-in for stag so tests can sign in. The suite covers signing in, the commission form with direct uploads and progress, every viewer (video playback and seeking, Markdown, converted PDFs, 3D models), description references, the person page filter and the home page image.

It needs a reachable S3 endpoint. Run just e2e-setup once to create a MinIO user limited to deers-io-e2e* buckets; each run then makes and removes its own bucket. Without that, the suite uses the bucket from .env and deletes only the objects it created. In CI, set E2E_S3_ENDPOINT, E2E_S3_ACCESS_KEY and E2E_S3_SECRET_KEY (and optionally E2E_BACKEND_BIN to a prebuilt server); nothing else needs to exist, including .env.

bun test in ui/ runs only the unit tests under ui/src.

Unit tests live next to the code they cover, in a #[cfg(test)] mod tests at the bottom of the file.

tests/ holds integration tests, which link the crate as an external caller and therefore only see its public API. They are split by area — people.rs, characters.rs, commissions.rs, authentication.rs — with public_api.rs holding the cross-cutting router behaviour: authentication coverage across every mutating route, fallbacks, body limits, and rate limiting. Shared fixtures, including the HTTP test client and the fakes for S3 and stag, live in src/util/test_support.rs.