hs-hath-1.4.0: README.md
# hs-hath
A [Hentai@Home](https://ehwiki.org/wiki/Hentai@Home) client written in Haskell, also on [Hackage](https://hackage.haskell.org/package/hs-hath). Supports local disk, SQLite, and S3-compatible (e.g. Cloudflare R2) cache backends, Dhall configuration, and Prometheus metrics at `/metrics`. Expect ~200 MiB RAM on average.
## Install
Prebuilt static binaries for Linux (`amd64`, `arm64`) and Windows (`x64`) are available on [GitHub Releases](https://github.com/pe200012/hs-hath/releases).
Multi-arch Docker images (`linux/amd64`, `linux/arm64`) are published to `ghcr.io/pe200012/hs-hath`. With [`compose.yaml`](compose.yaml):
```sh
mkdir cache download
cp client-login.example client-login # set clientId and key
echo HATH_PORT=443 > .env # port from your H@H settings page
docker compose up -d
```
To build from source, install [Stack](https://docs.haskellstack.org/) and SQLite 3, then run:
```sh
stack build
```
## Configuration
Copy `client-login.example` to `client-login` and fill it in. `hs-hath` reads `./client-login` unless given `-c FILE`.
```dhall
in ClientConfig::{
, clientId = "<YOURID>"
, key = "<YOURKEY>"
, downloadDir = "./download"
, cachePath = "./cache"
, cacheBackend = CacheBackend.CacheBackendFilesystem
, r2Config = None R2Config
}
```
`version`, `proxy` and `lruCacheSize` are deprecated and have no effect. If your file still has them, delete them along with their types and defaults (see `client-login.example`).
`cacheBackend` options:
* `CacheBackendFilesystem`: stores and serves files from `cachePath`, evicting least recently served files to stay under the H@H disk limit.
* `CacheBackendSQLite`: stores files in an SQLite database at `cachePath`, with no eviction. Checks every file at startup unless `--skip-startup-verify` is passed.
* `CacheBackendR2`: serves hits via presigned redirects, with no eviction. Requires `r2Config = Some { r2Endpoint = "https://<account id>.r2.cloudflarestorage.com", r2Bucket = "<bucket>" }`, `R2_ACCESS_KEY` and `R2_SECRET_KEY` in the environment, and a store returning `ETag`, `Content-Length`, and `Last-Modified` (missing `ETag` fails cache writes).
## Usage
Start the client with `hs-hath` (or `stack exec hs-hath` when built with Stack). Run `hs-hath --help` for all CLI options.
On Windows, stop the client with Ctrl+C so it notifies the server; closing the console window terminates it immediately.
With `docker run`, pass `-p <port>:<port>`, `--stop-timeout 45` (graceful shutdown takes up to 30s), and `-u <uid>:<gid>` matching the host files (default uid is `65532`).
## Metrics
Set `HATH_METRICS_TOKEN` (e.g. `openssl rand -hex 32`) to enable `/metrics` and `/admin/settings` with `Authorization: Bearer <token>`. Both endpoints return 404 when unset.
```yaml
scrape_configs:
- job_name: hath
scheme: https
authorization:
credentials: <token>
static_configs:
- targets: ["<host>:<port>"]
```
## Proxies and tunnels
Behind a reverse proxy on a loopback or private address, pass `--trust-proxy-headers` so flood control reads client IPs from `X-Forwarded-For`. The connection limit does not apply behind a local proxy.
With tunnels that rewrite the source IP (rathole, frp, port forwarding), every connection arrives from a local address, so flood control and connection limits do not apply and `/servercmd/` is authenticated by key alone. Rate-limit at the tunnel ingress.
## Startup and exit conditions
* Run it under a supervisor that restarts it: it exits on a failed login and with status 1 on a lost session.
* Refuses to start with an empty `Filesystem` or `SQLite` cache while more than 20 static ranges are assigned, or on `Filesystem` if the disk cannot hold the cache size set on the H@H settings page.
* On a failed connection test, it stays running without announcing itself so the port can be tested.
## License
GPL-3.0. See [`LICENSE`](LICENSE).