# koreader-ota

Serves an Apache/Swift-style directory listing of an R2 bucket at
`ota.mydomain.tld`, backed entirely by Cloudflare Pages Functions — no
static site rebuild needed when you add new builds.

## 1. Create the R2 bucket

```bash
npx wrangler r2 bucket create koreader-ota
```

## 2. Create the Pages project

```bash
npx wrangler pages project create koreader-ota
npx wrangler pages deploy public --project-name=koreader-ota
```

`public/` is intentionally empty (aside from `.gitkeep`) — every route falls
through to `functions/[[path]].js`, which reads straight from R2.

## 3. Bind the R2 bucket to the Pages project

Dashboard: Pages project → **Settings → Functions → R2 bucket bindings** →
add binding name `BUCKET` pointing at bucket `koreader-ota`.

(`wrangler.toml` in this repo declares the same binding for local dev via
`wrangler pages dev`.)

## 4. Add the custom domain

Pages project → **Custom domains** → add `ota.mydomain.tld`. If the domain
is on the same Cloudflare account, DNS is configured automatically.

## 5. Upload your build output

```bash
cd ~/Downloads/koreader
/path/to/koreader-ota/scripts/upload.sh
```

Uploads every file in the current directory to the bucket root, so
`ota.mydomain.tld/` will list them immediately — no redeploy required, since
the Function lists the bucket live on each request.

To keep nightly/stable builds in subfolders instead of one flat list, pass a
prefix: `./upload.sh . nightly` uploads into `nightly/`, and
`ota.mydomain.tld/nightly/` will list just that folder (with a `../` link
back up).

## Notes

- File type icons aren't included — just a plain link table, matching the
  screenshot you shared (Name / Size / Date).
- Sizes are shown in binary units (Ki/Mi/Gi) rounded to the nearest whole
  number, matching your example listing.
- If you also want KOReader's built-in updater to auto-discover these
  builds (not just a human-browsable page), you'd additionally need the
  small pointer files it looks for — e.g. a plain-text
  `koreader-kindlehf-latest-nightly` file containing the version string, and
  `.zsync`/`.kotasync` delta files — alongside the archives, following the
  same naming pattern as the official OTA server. Happy to help set that up
  too if you want it.
