This document provides comprehensive documentation for the HackClub CDN REST API endpoints. This is a part of Hack Club CDN project (It is the backend of the project)
All API endpoints require authentication using JWT tokens stored in cookies. The system supports:
- Slack OAuth integration for user authentication
- JWT tokens stored in HTTP-only cookies
- Automatic token refresh mechanism
All CDN endpoints are prefixed with /api/cdn/
GET /api/cdn/folders/
POST /api/cdn/folders/
POST Body Example:
{
"name": "My Folder",
"parent": null // or folder UUID
}}GET /api/cdn/folders/{id}/
PUT /api/cdn/folders/{id}/
PATCH /api/cdn/folders/{id}/
DELETE /api/cdn/folders/{id}/
}/
GET /api/cdn/folders/{id}/contents/
Returns both subfolders and files in the specified folder.
GET /api/cdn/folders/root/
Gets the root folder and its immediate contents.
GET /api/cdn/files/
Query Parameters:
folder_id: Filter by folder UUIDsearch: Search in filenamestype: Filter by type (images,videos,documents)page: Pagination page numberpage_size: Items per page (default: 20, max: 100)
POST /api/cdn/files/upload/
JSON Body:
{
"filename": "example.jpg",
"original_filename": "IMG_001.jpg",
"cdn_url": "https://cdn.example.com/files/abc123.jpg",
"file_size": 1048576,
"mime_type": "image/jpeg",
"md5_hash": "d41d8cd98f00b204e9800998ecf8427e",
"sha256_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"folder_id": "uuid-here"
}}Features:
- β Client-side CDN upload workflow
- β Duplicate detection using provided hashes
- β File metadata registration
- β Automatic thumbnail generation queue
- β Activity logging
GET /api/cdn/files/{id}/
PUT /api/cdn/files/{id}/
PATCH /api/cdn/files/{id}/
DELETE /api/cdn/files/{id}/
}/
GET /api/cdn/files/{id}/download/
Response:
{
"download_url": "https://cdn.example.com/files/abc123.jpg",
"filename": "example.jpg",
"size": 1048576,
"mime_type": "image/jpeg"
}}POST /api/cdn/files/{id}/star/
GET /api/cdn/files/starred/
GET /api/cdn/files/recent/
GET /api/cdn/shares/
POST /api/cdn/shares/
POST Body Example:
{
"resource_type": "file", // or "folder"
"resource_id": "uuid-here",
"permission_level": "view", // "view", "download", "edit", "admin"
"is_public": true,
"expires_at": "2024-12-31T23:59:59Z",
"allow_download": true,
"download_limit": 100
}}GET /api/cdn/shares/{id}/
PUT /api/cdn/shares/{id}/
DELETE /api/cdn/shares/{id}/
/
GET /api/cdn/shares/public/?token=your-public-token
GET /api/cdn/activity/
Returns user's activity history with pagination.
GET /api/cdn/analytics/
Returns analytics data for user's files.
GET /api/cdn/processing/
Returns status of background processing jobs (thumbnails, etc.).
GET /api/cdn/trash/
POST /api/cdn/trash/{id}/restore/
POST /api/cdn/trash/empty/
GET /api/cdn/dashboard/
Response Example:
{
"stats": {
"total_files": 150,
"total_folders": 25,
"total_size": 1073741824,
"total_size_human": "1.0 GB"
},
"recent_activity": [...],
"recent_files": [...],
"storage_by_type": [...]
}}GET /api/cdn/search/?q=search-term
POST /api/cdn/upload-0x0/
Form Data:
file: The file to upload
Description: This endpoint acts as a proxy to upload files directly to https://0x0.st using HTTPX for superior large file handling. The file is uploaded with streaming support, proper connection pooling, and the User-Agent "FriendlyUploader". The response from 0x0.st is returned directly to the client.
Large File Optimizations:
- Uses HTTPX instead of requests (better for >10MB files)es)
- Streaming upload prevents memory issues
- Smart timeout scaling based on file size
- Connection pooling for better performance
Features:
- β Direct proxy to 0x0.st
- β HTTPX-powered - Superior large file handling vs requests
- β Streaming uploads - Memory efficient for large files
- β Activity logging with retry tracking
- β Smart timeout handling (120s base + 30s per MB)
- β Automatic retry mechanism (3 attempts)
- β File size limit (200MB)
- β Connection pooling and limits optimization
- β Enhanced error handling with specific timeout types
- β Preserves original response format
Example Usage:
curl -H "Authorization: Bearer your-jwt-token" \
-F "[email protected]" \
http://localhost:8000/api/cdn/upload-0x0//Error Responses:
400- No file provided413- File too large (>200MB)MB)503- Connection error (service unavailable)504- Upload timeout (after 3 retry attempts)502- Other upload failures
id: UUID primary keyfilename: Current filenameoriginal_filename: Original uploaded filenamefolder: Foreign key to folderowner: Foreign key to user profilefile_size: Size in bytesmime_type: MIME typefile_extension: File extensionstorage_path: Path in storage systemcdn_url: CDN URL if availablethumbnail_url: Thumbnail URLpreview_url: Preview URLis_processed: Processing statusprocessing_status: Current processing statecreated_at: Upload timestamplast_accessed: Last access timestamp
id: UUID primary keyname: Folder nameparent: Foreign key to parent folderowner: Foreign key to user profilepath: Full folder pathis_root: Whether this is root foldercreated_at: Creation timestamp
id: UUID primary keyresource_type: "file" or "folder"resource_id: UUID of shared resourceowner: Share creatorshared_with_user: Target user (optional for public shares)permission_level: Access levelis_public: Public share flagpublic_token: Public access tokenexpires_at: Expiration timestampdownload_limit: Maximum downloadsdownload_count: Current download count
The API returns standard HTTP status codes:
200: Success201: Created400: Bad Request401: Unauthorized403: Forbidden404: Not Found409: Conflict (e.g., duplicate file)500: Internal Server Error
Error Response Format:
{
"error": "Error message",
"details": {...}
}}GET /api/slack/callback?code=oauth-code
POST /api/auth/retrieve
Body: {"auth_code": "short-lived-token"}
GET /api/auth/me
POST /api/auth/refresh
POST /api/auth/reset_password
Body: {"new_password": "...", "old_password": "..."}
β File Management
- Client-side CDN upload workflow (files uploaded directly to CDN)
- File metadata registration with duplicate detection
- Folder organization
- CDN file access and download URLs
- File versioning support
β Sharing & Permissionsions
- Public and private sharing
- Permission levels (view, download, edit, admin)
- Expiring shares
- Download limits
β Search & Discoveryvery
- Global search across files and folders
- File type filtering
- Recent files
- Starred items
β Analytics & Monitoringring
- Activity logging
- File access analytics
- Processing job status
- Storage usage stats
β Trash Management
- Soft delete with trash
- Restore functionality
- Auto-cleanup after 30 days
β Authentication
- Slack OAuth integration
- JWT token management
- Cookie-based auth for web clients
β External Services
- Proxy upload to 0x0.st with custom User-Agent
- Direct response passthrough
- Activity logging for external uploads
To get started:
- Install dependencies:
pip install -r requirements.txt(now includes HTTPX for better large file handling) - Run migrations:
python manage.py makemigrations && python manage.py migrate migrate - Create superuser:
python manage.py createsuperuser - Start server:
python manage.py runserver - Access API at:
http://localhost:8000/api/cdn/
The API is now fully functional and ready for frontend integration!