$ show cf-pages/Telegraph-Image
This is a self-hosted, free image hosting service (Telegraph-Image) built as a serverless application on Cloudflare Pages. It provides image upload, storage (Telegram Bot API or Cloudflare R2), serving with optional moderation (Workers AI or moderatecontent.com), and an admin dashboard (Vue-based) for managing images (list, block, delete, whitelist, edit names, toggle likes). The architecture follows a clean provider pattern for storage and moderation modules, uses middleware chaining via Cloudflare Pages Functions, and includes features like short links (KV-backed), anti-hotlinking, and deployment self-checks. The frontend is hybrid: a dependency-free modern homepage and an older Nuxt.js SPA for the admin panel. The codebase is well-tested with unit and e2e tests, but has technical debt from a legacy Nuxt frontend, deprecated `document.execCommand` usage, and reliance on external CDN resources for admin UI.
The LLM identified 3 files worth highlighting for reuse:
Implements HTTP Basic Authentication for Cloudflare Pages Functions. Provides `authenticated(request, env)` that checks `Authorization` header against environment variables (`BASIC_USER`/`BASIC_PASS` or `UPLOAD_BASIC_USER`/`UPLOAD_BASIC_PASS`). Returns `true/false` and a standard 401 response helper. This is a self-contained, reusable auth module that can be dropped into any Pages Functions project requiring simple credential checks, without pulling in external auth libraries.
Acts as a storage provider registry. Exports a function `getProvider(env)` that reads the `STORAGE_PROVIDER` env var and returns the appropriate module (telegram or r2). Each provider must implement `key`, `validateConfig`, `upload`, and `fetchFile`. This clean provider pattern allows adding new storage backends (e.g., S3, local filesystem) by simply dropping in a new file with the same interface and registering it. The abstraction decouples upload/serving logic from storage details, making the system extensible and testable.
Provides `createMockKV()` which returns an in-memory implementation of a KV namespace with `get`, `put`, `delete`, `list` methods and operation tracking (tracking count per method). Also includes `createMockCtx()` and `createMockEnv()` helpers. This utility is used across all unit tests to simulate Cloudflare KV bindings without network calls. It is a self-contained, reusable test helper that can be extracted for any Cloudflare Workers or Pages project needing a lightweight KV mock.