How artin0123/teimg works
Purpose and Delivered Surface
CloudFlare-ImgBed is a multi-backend file-hosting service with upload, browsing, management, deletion, public/random access, REST APIs, and WebDAV. The repository ships the compiled SPA rather than frontend source in frontend-dist/index.html and frontend-dist/js/app.4b2a8bcd.js; backend behavior is implemented as JavaScript edge/server routes.
Deployment Entry Points
Two runtime adapters expose the same functional route tree:
• Cloudflare Worker entry: deploy/worker/index.js, with generated routing/config support in deploy/worker/generate-routes.js and deploy/worker/wrangler.toml.
• Docker/Node server entry: deploy/server/index.js, bootstrapped through deploy/server/loader.mjs and deploy/server/register.mjs.
• Container deployment is defined by Dockerfile and docker-compose.yml. Deployment paths bridge Cloudflare-oriented APIs such as D1/R2 for local/server execution.
HTTP Route Domains
Cloudflare Pages Functions provide the main API surface under functions/:
• File read/delivery is handled by functions/file/[[path]].js behind functions/file/_middleware.js.
• Upload entry and multipart/chunk handling live in functions/upload/index.js, functions/upload/chunkUpload.js, and functions/upload/chunkMerge.js.
• WebDAV is a distinct protocol boundary at functions/dav/[[path]].js, with access middleware in functions/dav/_middleware.js.
• Management operations—listing, mutations, metadata, quota, batch backup/restore—are rooted in functions/api/manage/_middleware.js and functions/api/manage/list.js.
Authentication and Request Policy
Auth endpoints cover login, logout, admin login, reset, and session checks at functions/api/auth/login.js, functions/api/auth/adminLogin.js, and functions/api/auth/sessionCheck.js. Shared auth logic separates user/session/token concerns in functions/utils/auth/authCore.js, functions/utils/auth/sessionManager.js, and functions/utils/auth/tokenValidator.js. Route middleware creates the control boundary protecting uploads, file operations, management APIs, and WebDAV.
Storage and Metadata Plane
Content storage is provider-adapted: functions/utils/storage/telegramAPI.js, functions/utils/storage/discordAPI.js, functions/utils/storage/huggingfaceAPI.js, and functions/utils/storage/webdavAPI.js represent external channel integrations. Cloudflare R2 is supported by the server-side adapter deploy/server/r2Storage.js. Metadata, channel configuration, credentials, and visibility/security policy are handled in functions/utils/metadata/channelConfig.js, functions/utils/metadata/channelCredentials.js, and functions/utils/metadata/metadataSecurity.js.
Database and State Boundaries
Persistent metadata/configuration uses a database abstraction in functions/utils/databaseAdapter.js, with Cloudflare D1 access in functions/utils/d1Database.js; Docker/server emulation is provided by deploy/server/sqliteD1.js. The base schema and upgrades are versioned in database/init.sql and database/migrations/v2.2.1_add_tags_column.sql. Management and public listing routes query this plane rather than storage providers directly.
Primary Flows and Edge Services
Upload requests pass middleware, validate/process upload data, persist binary content through the selected storage channel, then record metadata/index state. Retrieval resolves a path through file middleware and storage/index logic; management mutates both metadata and remote objects. Public and random-image experiences are exposed through functions/api/public/list.js, functions/random/index.js, and functions/random/adaptive.js. Cache invalidation is centralized in functions/utils/purgeCache.js; Bing wallpaper retrieval is an external content integration at functions/api/bing/wallpaper/index.js.
Main entry points: databaseAdapter.js Database abstraction · [[path]].js File delivery · index.js Upload pipeline · list.js Management API
Components 22
Runtime adapters
- Compiled SPA · Delivered client application.
frontend-dist/index.html - Cloudflare Worker
deploy/worker/index.js - Docker Node server
deploy/server/index.js
HTTP surfaces
- File delivery
functions/file/[[path]].js - Upload pipeline · Handles regular, multipart, and chunked uploads.
functions/upload/index.js - WebDAV gateway
functions/dav/[[path]].js - Management API · Lists and mutates files, metadata, quota, and backups.
functions/api/manage/list.js - Auth API
functions/api/auth/login.js - Public listing
functions/api/public/list.js - Random images
functions/random/index.js - Bing wallpaper
functions/api/bing/wallpaper/index.js
Core services
- File access policy
functions/file/_middleware.js - WebDAV access policy
functions/dav/_middleware.js - Sessions and tokens
functions/utils/auth/authCore.js - Metadata security · Manages channel configuration, credentials, and visibility policy.
functions/utils/metadata/metadataSecurity.js - Cache purge
functions/utils/purgeCache.js
Storage and state
- Database abstraction
functions/utils/databaseAdapter.js - Cloudflare D1
functions/utils/d1Database.js - SQLite D1 emulation
deploy/server/sqliteD1.js - External storage channels · Telegram, Discord, Hugging Face, and WebDAV content backends.
functions/utils/storage/telegramAPI.js - R2 storage adapter
deploy/server/r2Storage.js - Database schema
database/init.sql
Connections 28
- Compiled SPA → Cloudflare Worker: served by
- Compiled SPA → Docker Node server: served by
- Cloudflare Worker → File delivery: routes requests
- Cloudflare Worker → Upload pipeline: routes requests
- Cloudflare Worker → WebDAV gateway: routes requests
- Docker Node server → File delivery: runs route tree
- Docker Node server → Upload pipeline: runs route tree
- File delivery → File access policy: protected by
- WebDAV gateway → WebDAV access policy: protected by
- Upload pipeline → Sessions and tokens: authenticates through
- Management API → Sessions and tokens: authenticates through
- WebDAV access policy → Sessions and tokens: validates access
- Auth API → Sessions and tokens: creates and checks sessions
- Upload pipeline → External storage channels: stores content
- Upload pipeline → Metadata security: records upload state
- File delivery → External storage channels: retrieves content
- File delivery → Database abstraction: resolves metadata
- WebDAV gateway → External storage channels: reads and writes objects
- Management API → Database abstraction: queries and mutates
- Management API → External storage channels: mutates remote objects
- Public listing → Database abstraction: lists indexed files
- Random images → Database abstraction: selects indexed files
- Metadata security → Database abstraction: persists configuration
- Database abstraction → Cloudflare D1: uses on Cloudflare
- Database abstraction → SQLite D1 emulation: uses on server
- Database schema → Cloudflare D1: defines schema
- Docker Node server → R2 storage adapter: adapts R2 access
- Management API → Cache purge: purges after mutations