# Sharey

A simple file sharing and pastebin service using Backblaze B2 cloud storage.

## Features

- 📁 **File Sharing**: Upload files and get shareable links
- 📝 **Pastebin**: Share text snippets with syntax highlighting support
- ☁️ **Cloud Storage**: Files stored securely in Backblaze B2
- 🔗 **Short URLs**: Clean, easy-to-share links
- 🎨 **Clean UI**: Simple, responsive web interface

## Setup

### Prerequisites

- Python 3.7+
- Backblaze B2 account with:
  - Application Key ID
  - Application Key
  - Bucket name

### Installation

1. **Clone the repository**
   ```bash
   git clone <your-repo-url>
   cd sharey
   ```

2. **Run the setup script**
   ```bash
   python setup.py
   ```
   
   This will automatically create a virtual environment and install dependencies.

3. **Configure B2 credentials**
   
   Sharey supports two configuration methods:
   
   **Option 1: JSON Configuration (Recommended)**
   ```bash
   # Edit config.json with your credentials
   nano config.json
   ```
   
   **Option 2: Environment Variables**
   ```bash
   # Edit .env file with your credentials  
   nano .env
   ```
   
   **Interactive Configuration**
   ```bash
   python config_util.py set
   ```

4. **Test B2 connection**
   ```bash
   python test_b2.py
   ```

5. **Run the application**
   ```bash
   # If using virtual environment (recommended)
   source venv/bin/activate
   python app.py
   
   # Or directly
   venv/bin/python app.py
   ```

The application will be available at `http://127.0.0.1:8866`

## Backblaze B2 Setup

1. **Create a Backblaze B2 account** at [backblaze.com](https://www.backblaze.com/b2/cloud-storage.html)

2. **Create an application key**:
   - Go to [App Keys](https://secure.backblaze.com/app_keys.htm)
   - Click "Add a New Application Key"
   - Name it "Sharey" or similar
   - Choose appropriate permissions (read/write access to your bucket)
   - Save the Key ID and Application Key

3. **Create a bucket**:
   - Go to [Buckets](https://secure.backblaze.com/b2_buckets.htm)
   - Click "Create a Bucket"
   - Choose "Public" if you want files to be publicly accessible
   - Note the bucket name

4. **Configure bucket for public access** (if desired):
   - Set bucket type to "Public"
   - Configure CORS settings if needed for web access

## File Organization in B2

Files are organized in your B2 bucket as follows:
```
your-bucket/
├── files/
│   ├── abc123.jpg
│   ├── def456.pdf
│   └── ...
└── pastes/
    ├── ghi789.txt
    ├── jkl012.txt
    └── ...
```

## Development

### Manual Installation

If you prefer not to use the setup script:

```bash
# Install dependencies
pip install -r requirements.txt

# Copy environment template
cp .env.example .env

# Edit .env with your credentials
nano .env

# Test configuration
python test_b2.py

# Run the app
python app.py
```

## Configuration

Sharey uses a flexible configuration system that supports both JSON files and environment variables.

### Configuration Files

- `config.json` - Main configuration file (recommended)
- `.env` - Environment variables (fallback/legacy support)

### Configuration Management

**View current configuration:**
```bash
python config_util.py show
```

**Interactive setup:**
```bash
python config_util.py set
```

**Validate configuration:**
```bash
python config_util.py validate
```

**Reset to defaults:**
```bash
python config_util.py reset
```

### Configuration Options

```json
{
  "b2": {
    "application_key_id": "your_key_id_here",
    "application_key": "your_application_key_here", 
    "bucket_name": "your_bucket_name_here"
  },
  "flask": {
    "host": "127.0.0.1",
    "port": 8866,
    "debug": true
  },
  "upload": {
    "max_file_size_mb": 100,
    "allowed_extensions": [".jpg", ".jpeg", ".png", ".gif", ".pdf", ".txt", ".doc", ".docx", ".zip", ".mp4", ".mp3"]
  },
  "paste": {
    "max_length": 1000000
  },
  "security": {
    "rate_limit_enabled": false,
    "max_uploads_per_hour": 50
  }
}
```

## License

MIT License - see [LICENSE](LICENSE) file for details.