Skip to content

FutureExcited/DOFS-cloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ DOFS File Gallery

A high-performance file gallery built with Cloudflare Workers, Durable Objects, and the DOFS (Durable Objects File System) module. Upload, store, and download files with real-time speed metrics and progress tracking.

⚑ Features

  • Real-time Upload Progress with live speed calculations and ETA
  • Real-time Download Progress with custom modal interface
  • Anti-DDoS Protection with smart rate limiting
  • Storage Limits (500MB per file, 10GB total)
  • Modern UI with drag & drop support
  • Speed Metrics for both uploads and downloads
  • Edge Storage with global distribution

πŸ—οΈ Architecture: DOFS vs Cloudflare R2

This project demonstrates file storage using DOFS (Durable Objects File System) instead of the traditional Cloudflare R2. Here's why this approach is interesting:

🌍 Edge-First Storage

  • DOFS: Files stored directly at the edge, closest to users
  • R2: Centralized storage with global CDN distribution

πŸ“ˆ Scalability Model

  • DOFS: One Durable Object per user/tenant - infinite horizontal scaling
  • R2: Single global bucket with shared limits

πŸ”’ Isolation

  • DOFS: Perfect tenant isolation (each user gets their own DO)
  • R2: Shared storage with application-level permissions

πŸ“Š Detailed Comparison Table

Feature DOFS (This Project) Cloudflare R2
Storage Location Edge nodes worldwide Regional with CDN
Latency Ultra-low (edge storage) Low (CDN cached)
Scalability Per-user Durable Objects Single global namespace
Isolation Perfect (DO per tenant) Application-level
File Size Limit 500MB (configurable) 5TB per object
Total Storage 10GB per DO (unlimited DOs) Unlimited
Concurrency High (distributed DOs) Very High
Consistency Strong (single DO) Strong
Setup Complexity Medium Low
Auth Integration Custom per DO Global IAM

πŸ’° Pricing Analysis

DOFS Costs (SQLite-backed)

Compute:
- Requests: 1M free, then $0.15/million
- Duration: 400K GB-s free, then $12.50/million GB-s
- Memory: 128MB allocated per active DO

Storage (Future):
- Data: 5GB free, then $0.20/GB-month
- Reads: 25B rows free, then $0.001/million rows
- Writes: 50M rows free, then $1.00/million rows

R2 Costs

Standard Storage:
- Storage: 10GB free, then $0.015/GB-month
- Class A Ops: 1M free, then $4.50/million
- Class B Ops: 10M free, then $0.36/million
- Egress: Free

Infrequent Access:
- Storage: $0.01/GB-month
- Class A Ops: $9.00/million
- Class B Ops: $0.90/million
- Data Retrieval: $0.01/GB

Cost Comparison Example (1TB, 1M operations/month)

Scenario DOFS Cost R2 Cost Winner
Small Scale (1GB, 100K ops) ~$0 (free tier) ~$0 (free tier) 🀝 Tie
Medium Scale (100GB, 1M ops) ~$20/monthΒΉ ~$6/month πŸ† R2
High Traffic (100GB, 10M ops) ~$25/monthΒΉ ~$40/month πŸ† DOFS
Multi-tenant (1000 users) ~$50/monthΒΉ ~$60/monthΒ² πŸ† DOFS

ΒΉ Estimated with future SQLite storage pricing Β² R2 + authentication/isolation overhead

🎯 When to Choose DOFS

βœ… Perfect For:

  • Multi-tenant applications (SaaS platforms)
  • High-performance requirements (gaming, real-time apps)
  • Edge-first architecture (global user base)
  • Strong isolation needs (compliance, security)
  • High request volumes (social media, chat apps)

❌ Not Ideal For:

  • Simple file storage (basic websites)
  • Large files (video streaming, backups)
  • Cost-sensitive projects (personal projects)
  • Infrequent access (archives, logs)

🎯 When to Choose R2

βœ… Perfect For:

  • Static websites (images, assets)
  • Content distribution (media, downloads)
  • Backup storage (databases, files)
  • Large file storage (videos, datasets)
  • Cost optimization (high storage, low compute)

❌ Not Ideal For:

  • Real-time applications (higher latency)
  • Multi-tenant isolation (shared namespace)
  • Edge computing (centralized storage)

πŸš€ Future Scaling Concepts

This is a proof of concept that could evolve into:

πŸ“ˆ Production Architecture

User Authentication β†’ Multiple DOs per User
β”œβ”€β”€ DO-User-Files (file storage)
β”œβ”€β”€ DO-User-Settings (preferences)  
β”œβ”€β”€ DO-User-Analytics (usage stats)
└── DO-User-Sharing (collaboration)

πŸ”§ Potential Enhancements

  • Per-user authentication (Auth0, Clerk, etc.)
  • Unlimited Durable Objects (one per user/tenant)
  • Cross-DO synchronization (shared files)
  • Advanced file operations (thumbnails, compression)
  • Real-time collaboration (WebSocket support)

πŸ› οΈ Getting Started

  1. Clone and Deploy
git clone <repo>
cd DOFS-speed
bun install
bun run deploy
  1. Configure Limits (optional)
// src/durable-object.ts
private uploadSizeLimit = 500 * 1024 * 1024; // 500MB
private totalStorageLimit = 10 * 1024 * 1024 * 1024; // 10GB
  1. Customize Rate Limits (optional)
// Different limits per operation type
maxRequests = endpoint === 'upload' ? 10 : 
              endpoint === 'download' ? 30 : 100;

πŸ“ API Endpoints

  • POST /api/upload - Upload files with progress tracking
  • GET /api/download/{filename} - Download with speed metrics
  • GET /api/files - List all uploaded files
  • GET /api/stats - Storage usage statistics
  • DELETE /api/delete/{filename} - Delete files

πŸ›‘οΈ Built-in Protection

  • Rate Limiting: 10 uploads, 30 downloads, 100 reads per minute
  • File Size Limits: 500MB maximum per file
  • Storage Quotas: 10GB total storage per DO
  • Input Sanitization: Filename cleaning and validation
  • Error Handling: Graceful failure with user feedback

Note: This is a hobby project demonstrating DOFS capabilities. For production use, add authentication, monitoring, and adjust limits based on your needs.

Features

  • πŸ“ File Upload: Drag & drop or click to upload multiple files
  • πŸ“₯ File Download: Download files with speed metrics
  • πŸ“Š Speed Metrics: Real-time upload/download speed measurement
  • πŸ—‘οΈ File Management: Delete files you no longer need
  • πŸ’Ύ Storage Stats: View storage usage and available space
  • πŸš€ No Login Required: Simple, open file sharing
  • πŸ“± Responsive Design: Works on desktop and mobile

Tech Stack

  • Cloudflare Workers: Serverless runtime
  • DOFS: Durable Objects File System for persistent storage
  • TypeScript: Type-safe development
  • Vanilla JavaScript: No frontend frameworks, just clean HTML/CSS/JS

Setup

  1. Install dependencies:

    bun install
  2. Generate Cloudflare types (optional):

    bun run cf-typegen
  3. Run locally:

    bun run dev
  4. Deploy to Cloudflare:

    bun run deploy

Configuration

The project is configured with:

  • Storage Limit: 10GB (configurable in src/durable-object.ts)
  • Chunk Size: 256KB for optimal performance
  • File Storage: Uses DOFS with SQLite backend in Durable Objects

API Endpoints

  • GET / - Serves the web interface
  • POST /api/upload - Upload files (multipart/form-data)
  • GET /api/files - List all uploaded files
  • GET /api/download/{filename} - Download a specific file
  • DELETE /api/delete/{filename} - Delete a specific file
  • GET /api/stats - Get storage usage statistics

File Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts           # Main worker entry point
β”‚   β”œβ”€β”€ durable-object.ts  # DOFS-powered Durable Object
β”‚   └── types.ts           # TypeScript type definitions
β”œβ”€β”€ package.json           # Dependencies and scripts
β”œβ”€β”€ wrangler.toml          # Cloudflare Workers configuration
β”œβ”€β”€ tsconfig.json          # TypeScript configuration
└── README.md              # This file

Speed Metrics

The application measures and displays:

Upload Metrics

  • Server-side timing: Actual time spent writing to DOFS
  • File size: Total bytes uploaded
  • Upload speed: Bytes per second (server-side)

Download Metrics

  • Server-side timing: Time to read from DOFS
  • Client-side timing: Total download time including network
  • Download speed: Calculated from server metrics
  • File size: Total bytes downloaded

Security Features

  • Filename sanitization: Prevents path traversal attacks
  • File size limits: Enforced by storage quota
  • No authentication: Intentionally open for simple file sharing

Customization

Storage Limit

Edit src/durable-object.ts and change:

this.fs.setDeviceSize(10 * 1024 * 1024 * 1024); // 10GB

Chunk Size

Edit the constructor in src/durable-object.ts:

this.fs = new Fs(ctx, env, { chunkSize: 256 * 1024 }); // 256KB

UI Styling

The HTML template in src/index.ts contains all CSS. Modify the styles to customize the appearance.

Development

Local Development

bun run dev

This starts Wrangler in development mode with hot reloading.

Type Checking

The project uses TypeScript with strict mode enabled. Run type checking with:

tsc --noEmit

Deployment

bun run deploy

This deploys to your Cloudflare Workers account.

Limitations

  • Single Durable Object: All files are stored in one global Durable Object instance
  • No authentication: Anyone can upload/download/delete files
  • No file versioning: Uploading a file with the same name overwrites the previous version
  • Memory usage: Large files are streamed but still use memory during processing

License

MIT License - feel free to use this project as a starting point for your own file sharing applications.

Contributing

This is a simple demonstration project. Feel free to fork and modify for your needs!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published