Skip to content
xav-iePublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

ream

ream

PDF tools you host yourself. Files never leave your machine or your Cloudflare account.

Deploy to Cloudflare

CI Release

ream is a small web app for everyday PDF chores. A Go server runs proven command line tools (qpdf, pdfcpu, ghostscript, img2pdf, poppler, libreoffice) behind an Astro UI. It holds no state: each request works in its own temporary folder, which is deleted when the response is sent. When idle it uses nothing, on a server or on Cloudflare.

ream's tools: Compress (PDF to PDF): Shrink file size. Images → PDF (Images to PDF): One image per page. Merge (PDF to PDF): Combine several PDFs into one. Office → PDF (Office to PDF): Word, Excel, ODF, and more. PDF → Images (PDF to ZIP): A PNG per page, as a zip. Reorder / extract (PDF to PDF): Pick a page sequence or range. Split (PDF to ZIP): One PDF per page, as a zip. Tools chain: report.docx goes through Office → PDF, then Compress, then Split, each continuing with the last result, to pages.zip.

The grids support drag to reorder, typed page ranges, and click to preview. Running a tool shows its result on the page, ezgif-style: the file's name and size, Save, Preview, and a "Continue with" row that hands a PDF result straight to the next tool (compress, then reorder, then split, and so on). The file rides in IndexedDB across the page load and never goes back to the server.

Deploy your own

Runs on Cloudflare Containers, which needs the Workers Paid plan ($5 a month). Personal use stays within the plan's included container time.

  1. Click Deploy to Cloudflare above. Cloudflare copies this repository into your GitHub account, builds the container image and deploys the Worker. It asks for REAM_ACCESS_TEAM_DOMAIN and REAM_ACCESS_AUD: enter your team domain (Zero Trust > Settings > Team domain, like yourteam.cloudflareaccess.com) and any placeholder for the AUD for now.
  2. Put Cloudflare Access in front of the Worker: Workers & Pages > your Worker

    Settings > Domains & Routes, turn on Access for workers.dev (or add a custom domain with its own Access application), and allow your email.

  3. Copy that Access application's Application Audience (AUD) Tag (Zero Trust > Access > Applications, open it) into the Worker's REAM_ACCESS_AUD secret (Worker > Settings > Variables and Secrets).

Until Access is set up, ream answers every request with 403: the Worker checks the Access token itself, so a forgotten setting fails closed instead of opening LibreOffice to the internet.

Limits on Cloudflare

  • Uploads: Cloudflare caps a request body at 100 MB, so the UI sends each file in 64 MiB pieces first. A file can be up to 2 GiB.
  • Cold start: after 5 idle minutes the container sleeps; the next request waits a few seconds for it to start.
  • One instance: every request goes to the same container, so all pieces of an upload land on the same disk.

Run it anywhere else

nix run github:xav-ie/ream                   # http://127.0.0.1:8086
docker build -t ream . && docker run -p 127.0.0.1:8086:8086 ream

The Nix package wraps every tool onto PATH, so it needs no other setup. On a host, run it under a systemd socket unit: ream adopts the socket (LISTEN_FDS), starts on the first request and exits after 5 idle minutes. Without socket activation it binds $REAM_HOST:--port (default 127.0.0.1:8086). There is no login, so put it behind something that has one.

Develop

nix develop                                   # Go, Node, pnpm and every CLI (or: direnv allow)
cd frontend && pnpm install && pnpm build     # emits frontend/dist
cd .. && REAM_WEBROOT=frontend/dist go run .  # http://localhost:8086

cd frontend && pnpm dev runs the Astro dev server for UI work. pnpm install at the root installs the Worker's tooling; pnpm exec wrangler dev runs the Worker and container locally, which needs Docker or Podman (the dev shell routes Podman through scripts/podman-docker, which drops the buildx flags Podman rejects).

Deploy through a release (see Releases) or from a machine with Docker. pnpm run deploy under Podman builds the image but fails to start it: Podman recompresses the layers on push, so the registry holds a different digest than the one wrangler recorded (IMAGE_REGISTRY_DOESNT_CONTAIN_IMAGE).

Test

nix flake check          # go vet + go test against the real CLIs, the package build, formatting
cd frontend && pnpm check   # eslint, knip, astro check, prettier, fallow
pnpm check:types && pnpm test   # the Worker and its Access check

nix fmt formats Nix, Go and the root files; the frontend keeps its own prettier (pnpm format) for the Astro plugin. Run pnpm types after changing wrangler.jsonc.

How it works

  • Server: main.go, standard library only. POST /api/<tool> takes a multipart upload, runs the tool with a 3 minute timeout, and streams the result back.
  • Chunked uploads: PUT /api/upload/<id>?offset=N writes one piece of a file at its offset; the tool request then names it as <id>/<filename>. Uploads are single use. Plain multipart files still work.
  • Cloudflare: src/worker.ts checks the Access token and forwards the request to one Ream container (standard-1: ½ vCPU, 4 GiB). The Dockerfile builds package.nix with Nix and copies only its runtime closure into an empty image, so the container runs exactly what nix build produces.
  • LibreOffice: libreoffice-headless.nix copies nixpkgs' prebuilt LibreOffice and deletes what --convert-to never loads (help, other languages, GTK, GStreamer, Java, Python), which also drops those dependencies: the closure goes from ~2.8 GB to ~900 MB without compiling anything.
  • Image layers: Cloudflare's runtime refuses to unpack a single layer that holds all of LibreOffice, though the same files over several layers start fine. The Dockerfile spreads any store path over 256 MB across four layers and the rest of the closure over 32.

Releases

Each user facing change adds a note with pnpm changeset. Every push to main keeps one "chore: version packages" PR up to date with the next version and its changelog; merging it tags v<version>, publishes a GitHub release and deploys the Worker (when the repository has the CLOUDFLARE_ACCOUNT_ID variable and the CLOUDFLARE_API_TOKEN and REAM_DOMAIN secrets; see .github/workflows/release.yml). package.nix reads its version from package.json, so the Nix package and the release always agree.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages