Skip to content

gin/temp-pdf

Repository files navigation

Temp PDF

Temporary storage and easy retrieval without needing to create user accounts.

Use it at: https://temp-pdf.pages.dev

Problem solved and how

Simplify printing stuff at hotel computers, without having to worry about deleting files left on hotel computers, clearing browser cache after printing, and having to worry about people around peeking at your login passwords.

Tricks used:

  • one-time access token hash that gets consumed on server once PDF is requested, so saved URL on the hotel computer browser history will not have access to your PDF
  • rate-limit bots from guessing URL and access pin
  • reduce bot access with CF Turnstile
  • ephemeral database that auto clears data on the server (like early versions of SnapChat)

Notable UI tricks:

  • bypasses iPhone popup blocker when sharing file to phones
  • 2 digits as access pin makes it simple for humans to remember (I copied GitHub 2FA backend)

Dev Notes

# Run the worker locally
npx -y wrangler pages dev . --kv=TEMP_PDF_STORAGE

# Reset the worker state
rm -rf .wrangler/state

Pre-deploy

# Note: The Turnstile public Site Key should be updated in `index.html`'s `data-sitekey` attribute before deploying. This can be done with `npm run sitekey`

# Set Frontend Site Key
# This automatically injects your public key into index.html
npm run sitekey -- YOUR_PUBLIC_SITE_KEY_HERE
# When testing, using this site key that always passes Cloudflare Turnstile widget
npm run sitekey -- 1x00000000000000000000AA


# Login to Cloudflare
npx wrangler login

# Create KV Namespace
npx wrangler kv namespace create TEMP_PDF_STORAGE

# Replace `id` in wrangler.toml using the output
[[kv_namespaces]]
binding = "TEMP_PDF_STORAGE"
id = "PASTE_THE_REAL_ID_HERE" 

Deploy

# Deploy to Cloudflare Pages
npx wrangler pages deploy .

# Set Backend Secrets. This can be found in Cloudflare Turnstile dashboard page.
wrangler pages secret put TURNSTILE_SECRET_KEY

About

Temporary storage and easy retrieval without needing to create user accounts

Resources

Stars

Watchers

Forks

Contributors