TelegramFileServer
A self-hosted cloud storage system based on Telegram. Supports multi-user logins, private file ownership, fast uploads/downloads, and a clean web or desktop interface for managing and streaming files.
Install / Use
/learn @pamod-madubashana/TelegramFileServerREADME
Telegram File Server
Telegram File Server is a powerful, self-hosted media server application that integrates with Telegram bots to provide file storage, organization, and streaming capabilities through a web interface. It now supports multi-user access with per-file ownership and access control.
Features
- Telegram Integration: Uses Pyrogram to connect with Telegram bots for file management
- Web Interface: Modern React frontend with TypeScript and TailwindCSS
- File Management: Organize files in folders, search, and filter by type
- Media Streaming: Built-in support for streaming videos, images, documents, and audio
- Authentication: Secure login with local accounts or Google OAuth
- Multi-User Support: Per-file ownership and access control
- Database Storage: MongoDB integration for storing file metadata
- Auto Updates: GitHub webhook support for automatic deployment updates
- Multi-Bot Support: Manage multiple Telegram bots from a single interface
Architecture
The application consists of three main components:
-
Backend Server (FastAPI):
- REST API for file operations
- Telegram bot management
- Authentication system
- MongoDB integration
-
Frontend Interface (React/Vite):
- File explorer UI with grid/list views
- Folder navigation and breadcrumb support
- File operations (copy, move, delete, rename)
- Responsive design with dark/light mode
-
Telegram Bots (Pyrogram):
- File upload/download from Telegram
- Media organization and categorization
- User interaction through commands
Frontend Repository
The frontend is maintained as a separate repository and included in this project as a git submodule:
- Repository: https://github.com/pamod-madubashana/FileServerApp
- Location:
src/frontend
To initialize the submodule, run:
git submodule update --init --recursive
Windows Desktop Application
A Windows desktop application is available, built with Tauri:
- Version: v1.0.1
- Features:
- Cross-platform file downloads (browser and desktop)
- Advanced download management with progress tracking
- File browsing and organization
- User authentication and profile management
- Multi-user file access control
- Settings customization
Download Links
Linux and macOS Desktop Applications
Desktop applications are also available for Linux and macOS, built with Tauri:
Download Links
Installation
Prerequisites
- Python 3.12+
- Node.js 16+
- MongoDB
- Telegram API credentials
Quick Setup
-
Clone the repository with submodules:
git clone --recurse-submodules <repository-url> cd fileServer -
If you've already cloned the repository without submodules, initialize them:
git submodule update --init --recursive -
Install Python dependencies:
pip install -r requirements.txt -
Install frontend dependencies:
cd src/frontend npm install -
Set up environment variables: Copy
.env.exampleto.envand configure your settings:API_ID=your_telegram_api_id API_HASH=your_telegram_api_hash TOKEN0=your_bot_token DATABASE_URL=your_mongodb_connection_string -
Run the application:
python __main__.py
Production Deployment
Using Systemd (Linux)
Run the installation script to set up a systemd service:
chmod +x install.sh
./install.sh
This creates a service named telegram-file-server that can be managed with:
tgserver start # Start the service
tgserver stop # Stop the service
tgserver restart # Restart the service
tgserver status # Check service status
tgserver logs # View live logs
Using Docker
Build and run with Docker:
docker build -t telegram-file-server .
docker run -p 8000:8000 telegram-file-server
Heroku Deployment
The application supports Heroku deployment through the provided app.json and heroku.yml.
Multi-User Model
The Telegram File Server now supports multiple users with per-file ownership and access control:
- Each file and folder is associated with an owner (user ID)
- Users can only access files they own
- Files uploaded via Telegram are associated with the Telegram account owner
- All file operations (view, move, copy, delete, rename) are restricted to owners
- Admin users can access all files
Configuration
Environment Variables
| Variable | Description | Required |
|----------|-------------|----------|
| API_ID | Telegram API ID | Yes |
| API_HASH | Telegram API Hash | Yes |
| TOKEN0 | Primary bot token | Yes |
| DATABASE_URL | MongoDB connection string | Yes |
| OWNER | Owner user ID | No |
| PORT | Web server port (default: 8000) | No |
| GOOGLE_CLIENT_ID | For Google OAuth | No |
| GOOGLE_CLIENT_SECRET | For Google OAuth | No |
Additional bot tokens can be added as TOKEN1, TOKEN2, etc.
Usage
Web Interface
After starting the server, access the web interface at http://localhost:8000 (or your configured port).
Features include:
- File browsing with folder navigation
- Virtual folders for media types (Images, Videos, Documents, Audio)
- Search functionality
- File operations (create folder, copy, move, etc.)
Telegram Commands
The bot supports various commands for file management:
/start- Welcome message- File upload/download through Telegram
API Endpoints
GET /- Application informationPOST /api/auth/login- User authenticationGET /api/files- List files in a path (filtered by owner)POST /api/folders/create- Create a new folder (assigned to current user)GET /api/bots/info- Get bot information
All file operations are restricted to the owner of the files. Full API documentation is available at /docs when the server is running.
Development
Backend Development
The backend is written in Python using FastAPI. Key directories:
src/Backend/- Web server implementationsrc/Database/- MongoDB models and connectionssrc/Telegram/- Bot implementationssrc/Config/- Configuration files
Frontend Development
The frontend uses React with Vite and is located in the src/frontend directory:
cd src/frontend
npm run dev # Start development server
npm run build # Build for production
Key directories:
src/frontend/src/components/- React componentssrc/frontend/src/hooks/- Custom React hookssrc/frontend/src/pages/- Page componentssrc/frontend/src/lib/- Utility functions
The frontend is a submodule repository hosted at https://github.com/pamod-madubashana/FileServerApp
Building the Windows Desktop App
To build the Windows desktop application using Tauri:
-
Navigate to the frontend directory:
cd src/frontend -
Install dependencies:
npm install -
Install Tauri CLI globally:
npm install -g @tauri-apps/cli -
Build the desktop app:
npm run tauri build
The built application will be available in src/frontend/src-tauri/target/release/bundle/ with installers for Windows.
Security
- Session-based authentication with secure middleware
- CORS protection
- Protected API endpoints
- Secure handling of Telegram credentials
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support, please open an issue on the GitHub repository or contact the maintainers.
