# PasteBin - A Modern Pastebin Clone A clean and modern pastebin website built with Python Flask and vanilla JavaScript, inspired by Hastepaste. Share code, text, and snippets with syntax highlighting, expiration options, and a beautiful dark/light theme. ## Features - **Clean, Modern UI** - Responsive design with dark/light theme support - **Syntax Highlighting** - Support for 19+ programming languages using Prism.js - **Expiration Options** - Set pastes to expire after 1 hour, 1 day, 1 week, or 1 month - **Easy Sharing** - Direct links, raw text view, and embed codes - **Download Support** - Download pastes with appropriate file extensions - **Mobile Friendly** - Works great on all devices - **Auto-save Drafts** - Never lose your work with automatic draft saving - **Keyboard Shortcuts** - Ctrl/Cmd + Enter to submit, Ctrl/Cmd + K to focus - **View Counter** - Track how many times a paste has been viewed - **Recent Pastes** - Browse recently created public pastes - **Error Handling** - Proper 404/410 pages for missing/expired pastes ## Supported Languages - Plain Text - JavaScript - Python - Java - C/C++ - C# - HTML/CSS - SQL - JSON/XML - Bash/PowerShell - PHP - Ruby - Go - Rust - Markdown ## Installation ### Prerequisites - Python 3.7+ - pip ### Setup 1. **Clone the repository:** ```bash git clone cd magic ``` 2. **Create a virtual environment:** ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` 3. **Install dependencies:** ```bash pip install -r requirements.txt ``` 4. **Run the application:** ```bash python app.py ``` 5. **Open your browser:** Navigate to `http://localhost:5000` ## Configuration ### Environment Variables You can customize the application using these environment variables: - `SECRET_KEY` - Flask secret key (default: 'your-secret-key-change-this') - `DATABASE` - Database file path (default: 'pastebin.db') ### Security For production deployment: 1. Change the `SECRET_KEY` in `app.py` or set the `SECRET_KEY` environment variable 2. Use a proper WSGI server like Gunicorn instead of the Flask development server 3. Set up proper error logging and monitoring ## Usage ### Creating a Paste 1. Visit the homepage 2. Enter an optional title 3. Select the programming language 4. Choose expiration time (or never expire) 5. Paste your content 6. Click "Create Paste" ### Viewing Pastes - **Regular View**: Formatted with syntax highlighting - **Raw View**: Plain text for copying or embedding - **Download**: Save as a file with proper extension ### Keyboard Shortcuts - `Ctrl/Cmd + Enter` - Submit the current paste form - `Ctrl/Cmd + K` - Focus on the content textarea ### Theme - Click the moon/sun icon in the navigation to toggle between light and dark themes - Theme preference is saved in localStorage ## Project Structure ``` magic/ ├── app.py # Main Flask application ├── requirements.txt # Python dependencies ├── pastebin.db # SQLite database (created automatically) ├── templates/ # Jinja2 templates │ ├── base.html # Base template with navigation │ ├── index.html # Create paste page │ ├── view.html # View paste page │ ├── recent.html # Recent pastes page │ ├── 404.html # Not found page │ └── 410.html # Expired page └── static/ # Static assets ├── css/ │ └── style.css # Main stylesheet └── js/ └── app.js # JavaScript functionality ``` ## API Endpoints ### Public Endpoints - `GET /` - Create paste page - `POST /create` - Create a new paste - `GET /` - View paste - `GET //raw` - View paste raw content - `GET /recent` - Recent pastes page - `GET /api/languages` - Get supported languages ## Database Schema The application uses SQLite with a single `pastes` table: ```sql CREATE TABLE pastes ( id TEXT PRIMARY KEY, -- Unique paste ID title TEXT, -- Optional title content TEXT NOT NULL, -- Paste content language TEXT DEFAULT 'text', -- Programming language created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP, -- Optional expiration date views INTEGER DEFAULT 0, -- View counter paste_type TEXT DEFAULT 'public' ); ``` ## Browser Support - Chrome 60+ - Firefox 60+ - Safari 12+ - Edge 79+ ## Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests if applicable 5. Submit a pull request ## License This project is open source and available under the MIT License. ## Deployment ### Using Gunicorn (Recommended for production) 1. Install Gunicorn: ```bash pip install gunicorn ``` 2. Run with Gunicorn: ```bash gunicorn -w 4 -b 0.0.0.0:8000 app:app ``` ### Using Docker (Optional) Create a `Dockerfile`: ```dockerfile FROM python:3.9-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . EXPOSE 5000 CMD ["python", "app.py"] ``` Build and run: ```bash docker build -t pastebin . docker run -p 5000:5000 pastebin ``` ## Security Considerations - Input validation and sanitization - XSS prevention through proper template escaping - CSRF protection via Flask's built-in mechanisms - Rate limiting (consider adding for production) - Content size limits (1MB default) ## Troubleshooting **Database errors**: Delete `pastebin.db` to reset the database **Permission errors**: Ensure the app has write access to the directory **Port conflicts**: Change the port in `app.py` or use environment variables **Theme not saving**: Check if localStorage is enabled in your browser ## Acknowledgments - Inspired by Hastepaste and modern pastebin services - Uses Prism.js for syntax highlighting - Built with Flask web framework