Building a modern, feature-rich R2 control panel using Next.js 15.2 and Cloudflare's API with improved functionality and user experience.
- Next.js 15.2
- TailwindCSS for styling
- React Query for data fetching and caching
- Framer Motion for animations
- React Icons for icons
- Cloudflare R2 API
- Tomato: #EF6351 - Primary action buttons, important alerts
- Salmon: #F38375 - Secondary actions, hover states
- Eerie Black: #1D1D1D - Main text, dark backgrounds
- Jet: #312D2D - Secondary backgrounds, borders
- Misty Rose: #FFECEA - Light backgrounds, highlights
- Use Tomato (#EF6351) for primary CTAs and important actions
- Use Salmon (#F38375) for secondary actions and hover states
- Use Eerie Black (#1D1D1D) for main content areas and text
- Use Jet (#312D2D) for secondary UI elements and borders
- Use Misty Rose (#FFECEA) for backgrounds and subtle highlights
- Ensure text contrast meets WCAG 2.1 standards
- Use darker shades for text on light backgrounds
- Maintain clear visual hierarchy using color combinations
- List buckets with infinite scroll
- Object browsing with infinite scroll
- Delete operations (single and bulk delete)
- Upload functionality with progress tracking
- Folder-like navigation using prefixes
- Implement advanced search functionality
- Search by filename
- Filter by file type
- Filter by date range
- Filter by size range
- Search within current "directory" (prefix)
- Real-time search results
- Image preview on hover
- Implement using Cloudflare Images API for thumbnails
- Cache thumbnails in browser for faster subsequent loads
- Support for common image formats (jpg, png, gif, webp)
- File type icons for non-image files
- Quick preview modal for detailed view
- Preview metadata (size, type, last modified)
- Implement virtual scrolling for large lists
- Progressive loading of thumbnails
- Client-side caching using React Query
- Optimistic updates for better UX
- Prefetching next page of results
- Smooth transitions using Framer Motion
- Loading skeletons for better loading states
- Toast notifications for operations
- Drag and drop upload zone
- Context menu for quick actions
- Breadcrumb navigation
- Grid/List view toggle
-
Display bucket metadata:
- Creation date
- Storage usage
- Operation counts (Class A and B)
- Public access status
-
Public Access Controls:
- Toggle public access on/off
- Display public URL when enabled
- Security warnings for public buckets
-
CORS Configuration:
- Add/Edit CORS rules
- Display existing CORS configuration
- Validate CORS syntax
-
Lifecycle Rules:
- Configure expiration policies
- Implement transition rules
- Schedule-based cleanup
-
Implement bucket creation flow
- Implement React Server Components (RSC) as default
- Use Client Components only for interactive elements
- Leverage RSC Payload for efficient client-server communication
- Implement proper component boundaries for optimal chunking
- Implement streaming for large data sets
- Use React Suspense for progressive loading
- Add loading.js files for automatic route segment streaming
- Implement partial prerendering for static/dynamic hybrid pages
- Use streaming metadata to prevent blocking initial page render
- Implement dynamic metadata generation without impacting Time to First Byte (TTFB)
- Configure htmlLimitedBots for SEO optimization
- Implement parallel route fetching
- Use route groups for better code organization
- Implement intercepting routes for modal views
- Use parallel routes for simultaneous data loading
- Implement server-side data fetching in Server Components
- Use React Query for client-side cache management
- Implement optimistic updates for better UX
- Use incremental static regeneration for semi-dynamic data
- Use next/image for automatic image optimization
- Implement responsive images with automatic srcset
- Use blur placeholder for better loading experience
- Implement automatic WebP conversion
- Enable Turbopack for faster development
- Implement proper code splitting
- Use dynamic imports for large dependencies
- Implement module/nomodule pattern for better browser support
- Implement proper caching headers
- Use stale-while-revalidate pattern
- Implement browser caching for static assets
- Use React Query's caching capabilities
- Initialize Next.js project with TypeScript
- Set up TailwindCSS and base styling
- Implement Cloudflare R2 API client
- Create basic layout and navigation
- Implement bucket listing
- Basic object management
- Upload functionality
- Basic search implementation
- Implement infinite scroll
- Add preview system
- Implement advanced search
- Add bulk operations
- Add animations and transitions
- Implement caching strategy
- Add virtual scrolling
- Optimize thumbnail loading
- Error handling improvements
- Loading states and feedback
- Cross-browser testing
- Performance optimization
-
Bucket Operations:
GET /accounts/{account_id}/r2/buckets POST /accounts/{account_id}/r2/buckets DELETE /accounts/{account_id}/r2/buckets/{bucket_name}
-
Object Operations:
GET /accounts/{account_id}/r2/buckets/{bucket_name}/objects PUT /accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key} DELETE /accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key}
-
Thumbnail Generation:
GET /accounts/{account_id}/images/v1/thumbnails/{object_id}
interface Bucket {
name: string;
creationDate: string;
objectCount: number;
size: number;
}interface R2Object {
key: string;
size: number;
lastModified: string;
etag: string;
httpMetadata?: {
contentType: string;
contentLanguage?: string;
contentDisposition?: string;
cacheControl?: string;
contentEncoding?: string;
};
customMetadata?: Record<string, string>;
}- Implement API Authentication middleware
- Added withAuth middleware for all API routes
- JWT token verification on all endpoints
- Error responses for unauthenticated requests
- Implement Role-Based Access Control (RBAC)
- Added withAdminAuth for admin-only operations
- Role checking in API middleware
- Different permission levels based on user roles
- Implement proper CORS configuration
- Use token-based authentication
- Rate limiting for API requests
- Validate file types and sizes
- Sanitize user inputs
- Add CSRF protection for state-changing operations
- Unit tests for utility functions
- Integration tests for API calls
- E2E tests for critical user flows
- Performance testing for large datasets
- Cross-browser compatibility testing
- Track API usage and limits
- Monitor error rates
- Collect performance metrics
- User behavior analytics
- Implement database-stored configuration via Drizzle ORM
- Create initial setup wizard for onboarding
- Add authentication with role-based access control
- Store configuration values in database instead of .env
- Allow configuration updates via admin dashboard
- Support secure password-based authentication
- Multi-bucket operations
- Version control integration
- Advanced file processing
- Custom metadata management
- Integration with other Cloudflare services
- Initialize Next.js 15.2 project with TypeScript
- Configure project name as "cloudflare-r2d2"
- Set up TailwindCSS
- Configure ESLint and Prettier
- Set up project directory structure
- Configure environment variables
- Add Cloudflare account ID
- Add API token configuration
- Set up environment validation
- Create base layout components
- Header with navigation
- Sidebar for bucket list
- Main content area
- Loading states
- Implement responsive design
- Mobile-friendly layout
- Collapsible sidebar
- Responsive grid/list views
- Set up R2 API client
- Create API wrapper class
- Implement error handling
- Add request/response types
- Implement basic bucket operations
- List buckets
- View bucket details
- Fetch bucket domains (public & Workers)
- Create bucket
- Delete bucket
interface BucketResponse {
name: string;
publicUrlAccess: boolean;
domains: string[]; // From public bucket access and Workers
bucketSize: string;
classAOperations: number;
classBOperations: number;
createdAt: Date;
}
interface PublicAccess {
enabled: boolean;
customDomain?: string;
}
interface WorkerDomain {
hostname: string;
service: {
r2_bucket?: string;
};
}- Implement object listing
- Basic metadata display (size, operations)
- Grid/list view
- File type icons
- Add object operations
- Upload files
- Download files
- Delete files
- Basic folder navigation
- Implement infinite scroll
- Virtual list for large datasets
- Scroll position management
- Prefetching
- Add preview system
- Image preview on hover
- File info modal
- Basic thumbnail generation
- Add preview optimizations
- Thumbnail caching
- Lazy loading
- Placeholder images
-
Current Approach:
- Using S3 API's ListObjectsV2Command for bucket metrics
- Size calculated by summing object sizes
- Operations approximated using object counts:
- Class A (writes) = KeyCount
- Class B (reads) = Contents.length
-
Future Improvements:
- Implement proper metrics collection using Workers
- Add CloudWatch-style metrics for operations
- Cache metrics data for better performance
- Add real-time updates for operation counts
-
Performance Considerations:
- Implement pagination for large buckets
- Add caching layer with React Query
- Use incremental loading for bucket contents
- Add background refresh for metrics
- Implement advanced filters (date range, size, type)
- Add unit tests and integration tests
- Complete documentation
- Add production optimizations
- Implement bucket creation flow
- Add basic search functionality
- Search by filename
- Filter by type
- Real-time search results
- Implement advanced filters
- Date range filter
- Size filter
- Type filter
- Implement Server Components
- Convert applicable components to RSC
- Optimize component boundaries
- Add streaming support
- Add caching layer
- Set up React Query
- Implement cache strategies
- Add optimistic updates
- Add animations & transitions
- Page transitions
- Loading animations
- Hover effects
- Implement error handling
- Error boundaries
- Toast notifications
- Retry mechanisms
- Basic testing
- Unit tests for utilities
- Integration tests for API
- Basic E2E tests
- Create documentation
- Setup instructions
- API documentation
- Usage guide
- Prepare for deployment
- Production optimizations
- Environment setup guide
- Deployment instructions
- Successfully list and navigate buckets
- Upload and download files
- Preview images and file information
- Basic search functionality
- Responsive and performant UI
- Error handling and loading states
- Working infinite scroll
- Basic file operations (create, delete)
- Focus on core functionality first
- Implement features incrementally
- Maintain performance from the start
- Test thoroughly at each step
- Document as we go
-
Public Access:
interface BucketPublicAccess { enabled: boolean; custom_domain?: string; public_url?: string; }
-
Worker Integration:
interface WorkerBinding { type: 'r2_bucket'; name: string; bucket_name: string; } interface WorkerService { id: string; name: string; bindings?: WorkerBinding[]; domains?: Array<{ hostname: string; service: string; }>; }
-
Domain Sources:
- Default R2 domain (
bucketname.accountid.r2.dev) - Custom domains configured for public access
- Worker domains with R2 bucket bindings
- Default R2 domain (
-
Implementation Status:
- Fetch bucket public access status
- Get default R2 domains
- Support custom domains
- Integrate Worker domains
- Add domain verification status
- Implement domain management UI