Commit graph

29 commits

Author SHA1 Message Date
Adam Brown
dd9774c34c
Self-service account deletion (#815)
Some checks are pending
Build CI / build (push) Waiting to run
Build CI / static-analysis (push) Waiting to run
Build CI / android-instrumented-tests (push) Waiting to run
Build CI / iOS compile & test (push) Waiting to run
Build CI / iOS UI tests (push) Waiting to run
PublishInternal / publish-google-play (push) Waiting to run
* Add self-service account deletion

Users can delete their account from the web dashboard danger zone. The
account is soft-deleted: locked out of login and sync, all stories
unpublished, pen name released, data retained for a configurable window
(accountDeletion.retentionDays, default 30 days) during which an admin
can restore it from the users page. A daily job permanently purges
accounts past the window. Admin accounts cannot be deleted; the guard is
enforced in the SQL, the service, and the UI.

* Harden account deletion edge cases from review

softDelete verifies the deleted flag actually landed before running its
destructive steps, and retries re-run the idempotent cleanup so a partial
failure heals; markDeleted leaves an already-deleted row untouched so
retries never extend retention. Tokens of soft-deleted accounts are
hidden inside the token query itself, restoring the whitelist-off
single-query bearer auth path. Re-registration against a soft-deleted
email returns the pending-deletion message instead of a misleading
"account exists", and the delete dialog warns that the email stays
reserved. Shared test account builder replaces per-file duplicates.
2026-08-01 02:59:30 -07:00
Adam Brown
5acba72867
Tell self-hosters when the server is not serving HTTPS (#800)
Some checks are pending
Build CI / build (push) Waiting to run
Build CI / static-analysis (push) Waiting to run
Build CI / android-instrumented-tests (push) Waiting to run
Build CI / iOS compile & test (push) Waiting to run
Build CI / iOS UI tests (push) Waiting to run
PublishInternal / publish-google-play (push) Waiting to run
Clients are HTTPS-only, but the Docker image serves plain HTTP, so a client
pointed at it fails its TLS handshake and reported only "Network error
connecting to /api/account/create". The handshake is rejected by Jetty's HTTP
parser before any route runs, so nothing about it reaches the server log
either, leaving unrelated UnsupportedProtocolVersionException entries as the
only visible clue.

Split the IOException arm of Api.makeRequest so a TLS failure names HTTPS and
the certificate or reverse-proxy requirement. Detection is expect/actual:
SSLException on JVM, message markers on iOS where NSURLSession carries nothing
else through.

Also fix the server URL field on the way in: cleanUpUrl stripped the scheme
with removeSuffix instead of removePrefix, so a pasted http:// URL failed
validation, and validateUrl required a dotted TLD, rejected capitals, and
admitted ports above 65535 that would crash the unguarded toInt() in url().

Fixes #790
2026-07-30 22:16:41 -07:00
Adam Brown
b1c06e791b
Add Docker support for self-hosting the sync server (#771)
* Add Docker support for self-hosting the sync server

Provide an official Docker image for self-hosting the Hammer sync server,
alongside the existing Java executable distribution.

- docker/Dockerfile: slim, non-root runtime image on a glibc base
  (eclipse-temurin:21-jre-jammy). Runs unprivileged because the embedded
  PostgreSQL binaries refuse to run as root, and stays on glibc because those
  binaries are not musl-compatible. Pins user.home to /data so a single volume
  holds the database, caches, keyring, and config. The image packages the
  pre-built application distribution rather than compiling from source, since
  :server depends on :base and a source build would need the Android SDK.
- docker/docker-compose.yml, config.example.toml, README.md: turnkey
  self-hosting with a data volume and optional host-managed config.
- .github/workflows/publish-docker.yml: builds the distribution and publishes a
  multi-arch (amd64/arm64) image to GHCR on release. One build serves both
  arches because the distribution is pure JVM bytecode with the embedded
  PostgreSQL binaries for every OS/arch bundled inside the jars.
- .dockerignore: trims the build context to just the built distribution.
- docs/HOW-TO-RUN-A-SERVER.md: document the Docker path and drop the stale
  "Eventually we'll add Docker images" note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014KJos31QSeA2YHkCU44nNZ

* Docker: pre-create data dir so config bind mount works unprivileged

Bind-mounting a config file at /data/hammer_data/config.toml would make Docker
create the parent dir as root when it doesn't already exist, leaving the
non-root server unable to write pgdata. Pre-create and chown /data/hammer_data
in the image so a named volume initializes with it hammer-owned, and clarify the
config provisioning paths in the Docker README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014KJos31QSeA2YHkCU44nNZ

* Docker: configurable host port and a BOM caveat for config.toml

Both found while testing the image end to end on Windows.

Compose merges `ports` lists by appending, so the hardcoded 8080 mapping could
not be overridden from an override file. Drive it from HAMMER_HTTP_PORT instead,
which is the usual escape hatch when the host port is already taken.

A config.toml saved as UTF-8 with a BOM fails with an UnexpectedTokenException
pointing at line 1, which reads like a syntax error in the file. Notepad and
PowerShell's Out-File -Encoding utf8 both write one, so call it out.

* Docker: note the one-time GHCR package visibility step

The package is created automatically on first publish, but may land private,
which would break the anonymous docker pull the docs point self-hosters at.
Left as a manual step because making a package public cannot be undone.

* Docker: note why the packages:write permission block is required

The repo default workflow token is read-only, so the explicit block is what
makes the GHCR push work rather than 403.

* Docker: document external PostgreSQL, add init for orphan reaping

Remote storage already worked (the DI picks RemotePostgresDatabase and the
schema initializer runs on first connect), but nothing in the Docker setup
showed how to use it. Add a commented-out postgres service with the matching
depends_on, and a README section covering it.

The service mounts its volume at /var/lib/postgresql: postgres 18+ images abort
startup when the mount is at the older /var/lib/postgresql/data path.

Call out that storage.remote.useSsl defaults to true, which fails against a
plain postgres container that serves no TLS.

init: true reaps orphans from the embedded PostgreSQL process tree. Shutdown was
already graceful without it - the start script execs, so the JVM is PID 1 and
runs its shutdown hooks on SIGTERM - but the JVM does not reap orphans.

* Docker: split out a dedicated hosting doc and fix review findings

Move the Docker hosting guide to docs/HOW-TO-RUN-A-SERVER-DOCKER.md and reduce
the inline section in the main guide, plus docker/README.md, to pointers so the
three cannot drift apart.

Fixes:
- Pin user.home through SERVER_OPTS rather than JAVA_OPTS. The start script
  appends both, so an operator setting JAVA_OPTS for heap was silently moving the
  data directory to /home/hammer, stranding the volume and starting an empty
  database.
- Publish the plain HTTP port on 127.0.0.1 by default, overridable with
  HAMMER_HTTP_BIND. Published ports bypass host firewall rules, so the previous
  0.0.0.0 default could put cleartext credentials on the internet.
- Warn that bindHosts must not be set under Docker; it binds the container
  loopback, leaving the server unreachable but still reporting healthy.
- Gate the release trigger on the +server tag convention so client-store-only
  releases no longer republish and move latest.
- Add a ref input so a dispatch that names a version builds that ref.
- Correct the claim that cert paths resolve relative to the data directory, and
  document that renewals need a container restart.
- generate-keyring example now writes to the volume with --out.
- storage.remote host is postgres, matching the compose service name.

Also trims the narrating comments across the Dockerfile, compose file, and
workflow.

* Docker: document running the admin CLI subcommands in a container

The embedded PostgreSQL holds an exclusive lock on pgdata, so subcommands that
read the database (prune-key --role content, --converge-dry-run) cannot run
while the server container is up. It fails safely rather than corrupting
anything, but the operator has to stop the server first, and nothing said so.

Adds a table of which commands need the database, the stop/run/start sequence,
and a key-rotation walkthrough noting that a rotated keyring only takes effect
on restart. The lock is embedded-specific; remote storage has no such
constraint.

* Docs: drop em dashes from the Docker hosting guide

* Docs: drop em dashes from the server hosting guide

* Remove PageSpeed PDFs accidentally added to this branch

These were untracked working-tree files swept in by a `git add -A`; they are
unrelated to the Docker work and stay on disk.

* Pin the docker/* actions to commit SHAs

Matches how every other third-party action in this repo is referenced, and
clears the supply-chain findings Codacy raised on the PR. Kept within the major
versions the workflow was written against rather than moving to the newer
majors, since the workflow has not run yet.

* Clarify why +server releases publish the Docker image

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-25 09:53:04 -07:00
Adam Brown
54fe6523e9
Configurable disk cache directory (#762)
The OG card and rendered story HTML caches were hard-coded to
hammer_data/cache. A [cache] block now sets the root directory and the
per-cache size bound, so an admin can move them to a scratch partition.

A configured directory resolves relative to the config file and is probed
for writability at startup: an unusable path aborts rather than degrading
to a permanent cache miss that just looks like a slow server.

* Close the gaps in cache directory validation

Validating after path resolution made the blank-directory guard dead: a
blank value resolves to the config file's own directory, which then looks
like a perfectly good absolute path, so the caches would land next to the
database instead of aborting. The cache block is now validated on the
parsed config, before resolution touches it.

The write probe only covered the cache root, but entries go in a
subdirectory per cache — a writable root holding a subdirectory owned by
someone else still degraded to a silent permanent cache miss, which is
the failure the probe exists to catch. Probing every subdirectory needs
their names in one place, so they move from string literals at the two
injection sites into a DiskCache enum.

Also: bound maxSizeMb, since a size given in bytes by mistake overflowed
the conversion into a negative cap that escaped the positive-value check;
collapse the 200 MB default to one definition; and read the e2e cache
helper's location from the config the server under test actually runs on.
2026-07-20 23:51:41 -07:00
Adam Brown
7ecc821ece
SEO metadata & rich link previews for the web frontend (#756)
* Cache static assets with Cache-Control headers

Add CachingHeaders so static assets get a public max-age — CSS/JS for a day,
images/fonts for a week — letting browsers skip revalidating them on every
navigation (ETags via ConditionalHeaders still catch changes once max-age
lapses). HTML and XML responses get no caching header. Also gate gzip on
minimumSize like deflate.

* Add canonical URLs, per-page titles, and author meta description

- Shared <head> emits <link rel="canonical"> and an optional <meta name="description">.
- Every page gets a self-referential canonical from its request path (query stripped)
  via withDefaults; the base URL prefers publicUrl and falls back to the request host.
- Story pages override the canonical to include ?page so each page is independently
  indexable (self-canonical), but never the ?p password param.
- Author and story pages get unique <title>s; author pages get a bio-derived description.

* Add OpenGraph and Twitter Card meta tags

Shared <head> emits og:site_name/type/title/description/url/image and the
twitter:card equivalents, reusing the title/description/canonical fields already
set. Defaults (type=website, image=site icon) come from withDefaults; author
pages set og:type=profile and story pages og:type=article.

* Add a branded 1200x630 default OpenGraph image

Ship a wide default share image (Hammer icon + wordmark) so social previews
render as summary_large_image cards instead of the small square icon. og:image
/twitter:image now point at it; pages can still override og:image later.

* Use branded per-type default OG images for authors and stories

Author and story pages now use type-specific static share cards (og-author /
og-story) instead of the generic default, so shared links read as an author
profile or a story at a glance. Zero setup — these ship as static assets.

* Add a generic size-bounded LRU disk cache

Stores arbitrary byte blobs keyed by string (SHA-256-hashed to a filename), with
atomic writes and approximate-LRU eviction by last-access time. put() self-bounds
to maxBytes; prune() and prune(maxAge) expose size/age maintenance for a scheduled
job. Reusable beyond the upcoming OG-image cache.

* Add OpenGraph image renderer and richLinkPreviews flag

Headless-AWT renderer for 1200x630 share cards (icon + wordmark + wrapped title
+ subtitle), loading the Kingthings TTF once. Adds the richLinkPreviews config
flag (default false; needs native font libs). Wiring to routes comes next.

* Wire dynamic OpenGraph images behind richLinkPreviews

With the flag on, author/story pages point og:image at per-entity endpoints
(/a/{pen}/og.png, /a/{pen}/{project}/og.png) that render personalized cards via a
disk cache (OgImageService over LruDiskCache) and 404 non-public entities. A
recurring job prunes the cache by age. With the flag off (default), pages fall
back to the branded static cards, so no font libraries are needed. Documents the
fontconfig/libfreetype6 requirement.

* Fix OG card layout so the subtitle never collides with the accent bar

Use fixed title/subtitle baselines instead of spacing relative to the title
height, so a 3-line (wrapped/truncated) title no longer pushes the subtitle off
the bottom. Slightly smaller title font to fit three lines cleanly.

* Redesign OG story card and localize share-card labels

Story card now leads with the title as the hero (inline open-book mark,
full-width wrap below), the author beneath it, and a footer attribution
pinned to the bottom. Secondary text is larger and darker for legibility
when the card is scaled down to a chat unfurl.

All card labels are localized: the renderer takes them as parameters and
the route resolves them via the existing ResourceBundle i18n. Reuses
public_story_by; adds og_attribution and og_author_subtitle (the latter a
{0} template filled with the server's own host). Cache keys are built from
the exact render inputs, so language and host variations regenerate.

* Add JSON-LD structured data to author, story, and home pages

A typed schema.org builder (kotlinx-serialization) emits ProfilePage/Person
for community author pages, Article for publicly-published stories, and
WebSite for the home page. The header template renders it into a
<script type="application/ld+json"> block when the model carries jsonLd.

Author-supplied text is escaped (< -> <) so it can't break out of the
script block. Structured data is emitted only for indexable pages.

* Add per-page titles and meta descriptions to public pages

Home, About, Community Authors, and Story Feed pages now set descriptive
<title>s and meta descriptions (reusing existing localized subtitles).
Public story pages get a meta description built from the title and author.
These feed the description/og/twitter tags the header already renders.

* Add Subresource Integrity to the htmx and Font Awesome CDN links

Pin the exact bytes of the two third-party assets so a compromised CDN
can't inject altered code: the browser blocks either file if its hash
doesn't match. Hashes verified against the served bytes (htmx cross-checked
across unpkg + jsdelivr, Font Awesome against cdnjs's published SRI);
crossorigin=anonymous added since both CDNs send Access-Control-Allow-Origin.

* Resolve dynamic OG images by stable id instead of caller-supplied strings

The share-card routes now take an account id / project UUID and render only
fields read back from the database — the pen name, story title, and the
subtitle host (from publicUrl config, never the request Host). Nothing the
caller supplies is drawn into the image or mixed into the cache key.

The author/story pages emit the dynamic og:image URL only when the subject
actually qualifies (community author; public, password-free story), matching
what the route will serve — so a share preview is never a broken 404 that
should have fallen back to the static card. A malformed project UUID is
rejected before the query so it can't raise a Postgres cast error. Rendering
moves off the event loop.

Adds findPublicProjectByUuid and route-level gating tests.

* Harden OG image caching, render concurrency, and cache stampede

- Scope Cache-Control by path: dynamic OG cards under /og cache for 30 days
  (the disk-prune window), /assets keep their type-based rules, everything
  else stays uncached. Previously any image response — including the dynamic
  OG PNGs — was matched by content type and cached for a week.
- Make LruDiskCache.getOrPut single-flight per key (striped locks) so a
  scraper burst on a viral link renders the card once, not once per request.
- Collapse the duplicated wrapText into a delegation to wrapTextIndented.
2026-07-20 00:17:23 -07:00
Adam Brown
5b17fbf429
Make clients HTTPS-only; add dev self-signed cert support (#743)
Remove the HTTP/HTTPS protocol picker and all ssl plumbing from the
client. Persisted server settings now always resolve to HTTPS, so a
legacy ssl=false server.json is upgraded on load. ServerSettings.ssl is
kept only as an internal seam for the plain-HTTP integration-test server.

Android: drop the permissive network_security_config so cleartext
traffic uses the secure platform default (blocked).

Server keeps its plain HTTP connector for reverse-proxy deployments. In
--dev with no sslCert configured, it now generates and persists a
self-signed keystore (hammer_data/dev-selfsigned.jks) and serves TLS on
a non-privileged port (8443 by default). The desktop --dev client trusts
that cert for loopback hosts only; remote hosts still get full cert and
hostname validation.
2026-07-17 00:52:41 -07:00
Adam Brown
94dae03333 Update repo references to Darkrock-Studios org
The repository moved from github.com/Wavesonics/hammer-editor to
github.com/Darkrock-Studios/hammer-editor. Update all URLs across
source, build scripts, web templates, docs, store metadata, and
test fixtures.
2026-07-13 16:31:11 -07:00
Adam Brown
2f49ae2f8d feat(server): auto-load config.toml from data directory
When no --config is passed, load ~/hammer_data/config.toml if present, else fall back to defaults. Doc renamed serverConfig.toml -> config.toml throughout.
2026-07-08 13:19:19 -07:00
Adam Brown
8fcc067446
Add a Google Analytics provider (#643)
Adds GA4 as a second web-analytics provider alongside Umami, selected via
analytics.type = "google" with an [analytics.google] measurementId block.

GA4 can fall back to tracking-pixel loads, so the AnalyticsProvider
interface gains imgSrcHosts() (empty for Umami) and the CSP builder folds
it into img-src. Download-click events flow through the existing neutral
data-track-* / hammerTrack bridge unchanged.
2026-06-23 20:48:56 -07:00
Lindsay
1ed25d978f
Minor changes to server run doc (#627)
minor updates, particularly regarding DNS requirements for access and bindHost usage in the reverse proxy configuration for security.
2026-06-21 18:04:07 -07:00
Adam Brown
cbaa7385d4
Add configurable server bind addresses (bindHosts) (#623)
The bind address was hardcoded to 0.0.0.0. Add a bindHosts config list
(default ["0.0.0.0"]) so self-hosters can restrict the server to loopback
only, e.g. bindHosts = ["127.0.0.1", "::1"] when running behind a reverse
proxy on the same host. Each address gets its own HTTP and HTTPS listener.

Distinct from the existing `host` field, which remains the public display
name shown on the setup page.

Closes #590
2026-06-20 00:58:29 -07:00
Wavesonics
d157ca83c4
Explain why self-signed won't work 2026-06-19 19:04:29 -07:00
Wavesonics
d5ea29151c
Remove self signed certs section
They won't work with client API calls, so they are worthless to us
2026-06-19 19:01:54 -07:00
Adam Brown
a08f42d8ee Clean up and clarify how to run server doc 2026-06-19 18:14:47 -07:00
Lindsay
3d52281e7f
Reverse proxy docs (#592)
* Update HOW-TO-RUN-A-SERVER.md

adding user and systemd setup.

* Update HOW-TO-RUN-A-SERVER.md

adding note about the installation directory fill.

* Update HOW-TO-RUN-A-SERVER.md

Update run.sh under linux

* Update HOW-TO-RUN-A-SERVER.md

Add caveat about using port 80.

* Update HOW-TO-RUN-A-SERVER.md

simplified bash run.sh and added where to put the run.sh script.

* Update HOW-TO-RUN-A-SERVER.md

Added steps for using Nginx as a reverse proxy for Hammer.

* Update HOW-TO-RUN-A-SERVER.md

Explicitly call out not to use the SSL steps  for Java when using Reverse Proxy.

* Update HOW-TO-RUN-A-SERVER.md

fixed LetsEncrypt paths for copy-pasta.
added full location block to https example instead of the [...].
added missing file link step.
added the missing http to https redirect as well as a note about LE doing it.
removed dhparams line because unnecessary and may not be auto generated.
2026-06-19 18:07:36 -07:00
Wavesonics
8d7ae2ab2a
Add testing to Server SSL cert loading
Update Server docs on setting up SSL
2026-06-19 17:25:17 -07:00
Adam Brown
7f5696236e Improved crypto migration story for existing servers 2026-06-18 02:29:42 -07:00
Adam Brown
408a2b720e Replace secret-storage design docs with a user-facing admin guide
The feature has shipped (PR1-PR5), so swap the temporary working docs for an
operator guide: SERVER-SECRET-STORAGE.md is now "Encryption at rest & key
management" (the keyring, enabling/disabling encryption, generate-keyring /
inspect-keyring / rotate-key, --converge-dry-run, deleting an old key, and
upgrading an already-encrypted server). Linked from HOW-TO-RUN-A-SERVER.md.

Deletes the implementation plan doc.
2026-06-17 02:01:58 -07:00
Lindsay
6ed6782372
Adding systemd example (#581) 2026-06-11 00:46:19 -07:00
Adam Brown
cd48c3289e
Allow more run-time config of umami 2026-06-04 23:04:35 -07:00
Adam Brown
b2c42b1aa9
Add configurable web analytics for the server web frontend (Umami) (#534)
Introduce an extensible [analytics] server config section. The first
supported provider is Umami; the design (provider enum + per-provider
config block + AnalyticsProvider abstraction/factory) allows adding more
providers later without touching the rendering or CSP wiring.
2026-05-31 21:46:28 -07:00
Adam Brown
519b8a8542
Document PostgreSQL storage and the SQLite-to-Postgres migration 2026-05-21 02:00:52 -07:00
Adam Brown
467f6cea2c
Update HOW-TO-RUN-A-SERVER.md 2026-01-13 01:32:31 -08:00
Adam Brown
dc7283f4df Updated the server documentation
This should help get people up and running on different platforms and addresses some of the newer sever features we've added
2026-01-12 20:44:12 -08:00
Adam Brown
6b0ff43c48 Implement the new Community server feature 2026-01-10 18:06:13 -08:00
Adam Brown
52ff3693cd Implemented an Email system 2026-01-07 19:18:22 -08:00
Adam Brown
9b1142940f Tweak server docs 2025-12-26 00:03:21 -08:00
Adam Brown
c4b7a7ab72 Added a new ServerConfig system 2025-12-19 23:10:57 -08:00
Wavesonics
5e63f4ff71 Reorganize docs 2023-08-26 21:56:30 -07:00
Renamed from HOW-TO-RUN-A-SERVER.md (Browse further)