Skip to content
t-scheiberPublic

About

Phone-friendly PDF viewer for a drone pilot's papers, such as insurance and registration, behind a passphrase screen. Next.js.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Drone Documents

A small Next.js app that shows a drone pilot's papers (insurance, registration, licence) as a phone-friendly list of PDFs behind a passphrase screen. The idea is to pull the papers up quickly when an authority asks for them.

Live: https://drone.thomasscheiber.com

Demo

The login screen shows a demo passphrase: demo. It opens three fictional sample PDFs made out to "Max Mustermann", each marked SAMPLE. The "View demo" button below the form does the same thing in one click.

A demo session only ever sees the samples. The real documents need the owner passphrase.

What it does

  • app/login.tsx shows the passphrase form and the demo hint.
  • app/pdf-viewer.tsx shows one card per PDF. "View Document" opens the PDF in an iframe modal and "Download PDF" saves it. In demo mode a banner says the documents are fictional.
  • The layout uses responsive Tailwind classes and 44 px touch targets. There is no service worker, so nothing works offline.
  • Logout deletes the session cookie.

How access works

The server checks the passphrase and hands out a session. The browser never sees the owner passphrase.

  1. POST /api/session takes { "passphrase": "..." }. demo gives the demo role. The value of DRONE_PASSPHRASE gives the owner role. Both comparisons ignore case and surrounding spaces. A wrong passphrase gets a 401 after a short delay.
  2. The role is stored in an httpOnly cookie, drone-session, signed with HMAC-SHA256 using SESSION_SECRET. It expires after 12 hours. Changing the role in the cookie breaks the signature, so the server treats the request as signed out.
  3. GET /api/documents returns the document list for the role in the cookie. Demo sessions get the sample list. Owner sessions get the real list.
  4. GET /api/documents/<file name> is the only way to read a real PDF. It answers 401 without a session and 403 for a demo session, for every file name. For an owner it only serves a file whose name exactly matches a PDF in the real folder, so paths like ../ do not work.

The code for this is in lib/session.ts, lib/documents.ts and app/api/.

The demo passphrase is checked first and always gives the demo role, so DRONE_PASSPHRASE must not be demo. If it is, or if it is unset, nobody can log in as owner.

Where documents live

Sample PDFs are committed in public/demo-documents/ and served as static files. They are generated by scripts/generate-demo-pdfs.js (bun run generate-demo-pdfs), which builds them by hand without extra dependencies.

Real PDFs are never committed and never placed in public/. They go into private-documents/ (gitignored), or into the folder named by DOCS_DIR. The list is read from that folder on each request, so the file names do not ship in the JavaScript bundle.

An optional documents.json in the same folder sets the order, titles and descriptions:

[
  { "file": "registration.pdf", "title": "Operator registration", "description": "Austro Control, valid until 11.01.2027" }
]

PDFs listed there come first, in that order. PDFs not listed follow with a name made from the file name. The manifest itself is never served.

scripts/sync-documents.js runs before dev and build and fills the real folder. It does nothing unless one of these is set:

  • DOCS_SOURCE_DIR: a local folder, copied recursively.
  • DOCS_ARCHIVE_URL: a zip file, downloaded and extracted. It follows up to 5 redirects. Optional auth for the download comes from DOCS_ARCHIVE_TOKEN (with DOCS_ARCHIVE_AUTH_HEADER and DOCS_ARCHIVE_AUTH_SCHEME), from DOCS_ARCHIVE_BASIC_USER and DOCS_ARCHIVE_BASIC_PASS, or from DOCS_ARCHIVE_HEADER_KEY and DOCS_ARCHIVE_HEADER_VALUE.

When it runs, it first deletes the existing real folder. It then moves every PDF from subfolders into the top level and renames duplicates with a numeric suffix.

Card names and descriptions for real PDFs come from the file name. For example, a name containing "haftpflicht" gets "Liability insurance policy document".

Stack

Versions come from package.json.

  • Next.js 16.4 with the App Router, React 19.3, TypeScript 6.0
  • Tailwind CSS 4.3 through @tailwindcss/postcss
  • adm-zip 0.6 for the zip download
  • ESLint 10 with typescript-eslint 8
  • bun as the package manager (bun.lock)

TypeScript is held at 6.x because typescript-eslint 8.72 refuses to load under TypeScript 7.

Run it

bun install
cp .env.example .env.local   # then set DRONE_PASSPHRASE and SESSION_SECRET
bun run dev                  # http://localhost:3000

The demo works without any environment variables. To try the owner view, put a few PDFs into private-documents/ and log in with DRONE_PASSPHRASE.

For a production build:

DOCS_SOURCE_DIR=/path/to/pdfs bun run build
DRONE_PASSPHRASE=your-passphrase SESSION_SECRET=long-random-string bun run start

DRONE_PASSPHRASE and SESSION_SECRET are read at runtime, so changing them needs a restart, not a rebuild.

Deployment

The live site runs on a self-hosted Coolify instance with the nixpacks build pack. A push to main triggers a deploy through the GitHub webhook. Set DRONE_PASSPHRASE, SESSION_SECRET and a document source (DOCS_SOURCE_DIR, DOCS_ARCHIVE_URL or DOCS_DIR on a mounted volume) as environment variables in Coolify.

Scripts

Script What it does
dev Sync real documents, start next dev --turbopack
build Sync real documents, run next build
start Run next start on the built app
lint Run ESLint
sync-documents Run the sync script only
generate-demo-pdfs Rewrite the sample PDFs in public/demo-documents/

There is no test suite. Type-check with bunx tsc --noEmit.

Environment variables

Variable Used by Purpose
DRONE_PASSPHRASE /api/session Owner passphrase, read at runtime. Owner login is off if it is unset or demo.
SESSION_SECRET /api/session Key for signing session cookies. If unset, a random key is made at startup and every restart logs everyone out.
DOCS_DIR sync script, API Folder with the real PDFs. Default private-documents/.
DOCS_SOURCE_DIR sync script Local folder of PDFs to copy in
DOCS_ARCHIVE_URL sync script URL of a zip with PDFs, ignored if DOCS_SOURCE_DIR is set
DOCS_ARCHIVE_* sync script Download auth, listed above

NEXT_PUBLIC_DRONE_PASSPHRASE from older versions is no longer read. It put the passphrase into the browser bundle.

About

Phone-friendly PDF viewer for a drone pilot's papers, such as insurance and registration, behind a passphrase screen. Next.js.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages