|
|
||
|---|---|---|
| static | ||
| templates | ||
| .gitignore | ||
| README.md | ||
| app.py | ||
| config.json | ||
| gunicorn.conf.py | ||
| production.py | ||
| requirements.txt | ||
| setup.py | ||
| wsgi.py | ||
README.md
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
-
Clone the repository:
git clone <repository-url> cd magic -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Run the application:
python app.py -
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:
- Change the
SECRET_KEYinapp.pyor set theSECRET_KEYenvironment variable - Use a proper WSGI server like Gunicorn instead of the Flask development server
- Set up proper error logging and monitoring
Usage
Creating a Paste
- Visit the homepage
- Enter an optional title
- Select the programming language
- Choose expiration time (or never expire)
- Paste your content
- 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 formCtrl/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 pagePOST /create- Create a new pasteGET /<paste_id>- View pasteGET /<paste_id>/raw- View paste raw contentGET /recent- Recent pastes pageGET /api/languages- Get supported languages
Database Schema
The application uses SQLite with a single pastes table:
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is open source and available under the MIT License.
Deployment
Using Gunicorn (Recommended for production)
-
Install Gunicorn:
pip install gunicorn -
Run with Gunicorn:
gunicorn -w 4 -b 0.0.0.0:8000 app:app
Using Docker (Optional)
Create a 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:
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