Unlimited Zero-Cost Cloud Storage for the Gothwad Technologies Ecosystem (drive.bansify.com).
Gothwad Drive v4.0 combines a direct browser-to-Telegram MTProto storage engine (@mtcute/web) with a Cloudflare Worker + D1 edge layer for silent .bansify.com Single Sign-On (SSO), AES-256-GCM encrypted MTProto session vaults, cached folder tree hydration, and short public share links (/s/:shareId).
- Zero-Cost Hybrid Storage Model:
- File Bytes: Stream directly between the user's browser and Telegram Datacenters over WebSocket MTProto (
@mtcute/web) with 20 MB chunk manifests and a Service Worker (public/stream-sw.js) supporting206 Partial Contentbyte-range streaming. - Identity, Encrypted Session Vault & Share Metadata: Stored in Cloudflare D1 (
drive, database IDdfefd813-244a-47f1-8f5a-8d5c15ba3162) behind thedriveCloudflare Worker (drive.bansify.com/api/*).
- File Bytes: Stream directly between the user's browser and Telegram Datacenters over WebSocket MTProto (
- Single-Identity-Verification Bootstrap (
GET /api/drive/bootstrap) & Truthful Error Classification:- Verifies
.bansify.comSSO identity once againsthttps://api.bansify.com/api/auth/meand returns both the verified identity and the selected user's cloud vault state in a single round-trip while forwarding all rotatedSet-Cookieheaders individually. - Strictly separates confirmed anonymous responses (
401or200 { authenticated: false }) from service and routing errors (5xx,429, network failures, timeouts, redirects, malformed JSON, or HTML responses when/api/*is caught by the SPA catch-all). - Renders the verified account shell (
Header, account switcher, and cached folders) immediately after identity verification without blocking behind optional avatar downloads or background MTProto indexing.
- Verifies
- Versioned AES-256-GCM Encrypted Cloud Session Vault & Ciphertext Protection:
- Encrypts the user's
@mtcute/websession string per user using HKDF-SHA256 + WebCryptoAES-GCM(key_version = 2withuser_idAdditional Authenticated Data, while remaining backward-compatible withkey_version = 1rows and supporting bothDRIVE_ENCRYPTION_KEYandVAULT_MASTER_KEY). - Security Note on Encryption Keys: Setting the
DRIVE_ENCRYPTION_KEYsecret in Cloudflare Worker secrets is required to keep the master encryption key separate from the D1 database. Thesystem_keysD1 auto-bootstrap key is a zero-configuration fallback and does not protect against a full D1 database dump unlessDRIVE_ENCRYPTION_KEYis configured as a Worker secret. - Distinguishes genuinely missing vaults (
vaultStatus: "missing") from unreadable/corrupted ciphertext (vaultStatus: "corrupt"). Unreadable ciphertext in D1 is locked against silent overwrite (409 vault_corrupt_locked) unless the user explicitly confirms recovery replacement.
- Encrypts the user's
- Confirmed Vault Migration & Strict Multi-Account Isolation:
- Keeps runtime Telegram sessions in
MemoryStorageand only scrubs legacylocalStoragesessions afterPUT /api/drive/vaultsucceeds. - Isolates IndexedDB folder caches (
GothwadDriveDB) by${gothwadUserId}:${tgUserId}:${chatId}:${topicId}, tags legacy local sessions by owner to prevent cross-account auto-import, and verifiesX-Gothwad-Expect-Useron vault mutations (409 account_mismatch). - Separates non-destructive local disconnect / SSO sign-out from explicit, user-confirmed remote vault unlinking (
DELETE /api/drive/vault).
- Keeps runtime Telegram sessions in
├── public/
│ ├── _redirects # Cloudflare Pages SPA routing (/s/*, /u/*, /*)
│ └── stream-sw.js # Range-request streaming Service Worker
├── sql/
│ ├── 00_d1_console_bootstrap.sql # Remote-safe D1 bootstrap SQL (zero PRAGMA)
│ └── 01_drive_schema.sql # Canonical D1 schema (system_keys, drive_vaults, drive_shares)
├── worker/
│ ├── wrangler.toml # Worker config (name = "drive", route drive.bansify.com/api/*)
│ └── src/
│ ├── index.ts # Worker router (/api/health, /api/me, /api/drive/bootstrap, /api/drive/*)
│ ├── auth.ts # Upstream SSO verification & Set-Cookie multi-header forwarding
│ ├── crypto.ts # Versioned HKDF-SHA256 + AES-256-GCM per-user vault encryption
│ ├── vault.ts # Bootstrap & GET / PUT / DELETE /api/drive/vault handlers
│ ├── shares.ts # POST /api/drive/shares & GET /api/drive/shares/:id handlers
│ ├── schema.ts # Cold-start idempotent ensureSchema(env.DB)
│ ├── http.ts # JSON, CORS, and CSRF Origin verification helpers
│ └── types.ts # Worker TypeScript interfaces
├── src/
│ ├── config/ # Brand domain & MTProto dual-signature constants
│ ├── lib/ # Modular SSO/bootstrap/vault client, MTProto, scoped IndexedDB, radar
│ ├── hooks/ # Generation-safe React hooks (useAuth, useSsoVaultBootAndSync, useDrive, useFiles)
│ ├── components/ # Modular UI components (every file strictly <= 500 lines)
│ └── styles/ # Theme tokens, utilities, and keyframe animations
└── tests/
├── drive.test.mjs # Static, SQL, crypto, Worker lifecycle, <=500-line & English-only gates
└── behavioral.test.mjs # Behavioral regression suite (timeouts, 503/HTML, corrupt vault lock, isolation)
# Install dependencies
npm install
# Run both verification suites (tests/drive.test.mjs + tests/behavioral.test.mjs)
npm test
# Lint (0 warnings) and build the code-split production SPA bundle
npm run lint
npm run build
# Verify Cloudflare Worker dry-run bundle
npx wrangler deploy --dry-run -c worker/wrangler.toml- Bootstrap D1 Database (
drive):- Open Cloudflare Dashboard -> Workers & Pages -> D1 SQL Database ->
drive(dfefd813-244a-47f1-8f5a-8d5c15ba3162) -> Console, pastesql/00_d1_console_bootstrap.sql, and click Execute.
- Open Cloudflare Dashboard -> Workers & Pages -> D1 SQL Database ->
- Configure Worker Secret & Deploy (
worker/wrangler.toml):- Set the encryption secret in Worker secrets so the master key is stored outside D1:
npx wrangler secret put DRIVE_ENCRYPTION_KEY -c worker/wrangler.toml - Deploy the Worker and ensure route
drive.bansify.com/api/*is attached in thebansify.comzone:npx wrangler deploy -c worker/wrangler.toml
- Set the encryption secret in Worker secrets so the master key is stored outside D1:
- Deploy Frontend (Cloudflare Pages):
- Build command:
npm run build, Output directory:dist, Custom domain:drive.bansify.com.
- Build command: