# Sharey Configuration System

## Overview

Sharey now features a comprehensive JSON-based configuration system that replaces environment variables with a more structured and feature-rich approach.

## Configuration Files

### Primary Configuration: `config.json`
```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
  }
}
```

### Fallback: Environment Variables
For backwards compatibility, Sharey still supports `.env` files and environment variables.

## Configuration Management Tools

### Setup Script: `setup.py`
- Creates `config.json` from template
- Sets up virtual environment
- Installs dependencies
- Validates configuration

### Configuration Utility: `config_util.py`
```bash
python config_util.py show      # Display current config
python config_util.py validate  # Validate configuration
python config_util.py set       # Interactive setup
python config_util.py reset     # Reset to defaults
```

### Test Utility: `test_b2.py`
- Tests B2 connection
- Validates credentials
- Shows configuration summary

## New Features

### File Upload Controls
- **File size limits**: Configurable max file size in MB
- **File type restrictions**: Whitelist of allowed extensions
- **Validation**: Automatic file type checking

### Paste Controls
- **Length limits**: Configurable maximum paste length
- **Validation**: Automatic length checking

### Flask Configuration
- **Host/Port**: Configurable server settings
- **Debug mode**: Environment-specific settings

### Security Features (Future)
- **Rate limiting**: Configurable upload limits
- **Extensible**: Ready for additional security features

## Configuration Loading Priority

1. **config.json** (if exists)
2. **Environment variables** (fallback)
3. **Built-in defaults** (last resort)

## Benefits of JSON Configuration

### ✅ **Structured Data**
- Hierarchical organization
- Type safety (strings, numbers, booleans, arrays)
- Better validation

### ✅ **Feature Rich**
- Upload restrictions
- File type filtering
- Paste length limits
- Server configuration

### ✅ **User Friendly**
- Interactive setup utility
- Configuration validation
- Clear error messages
- Comprehensive documentation

### ✅ **Developer Friendly**
- Easy to extend
- Version controllable (with secrets excluded)
- IDE support with syntax highlighting
- Better tooling support

### ✅ **Backwards Compatible**
- Still supports .env files
- Smooth migration path
- No breaking changes

## Migration from .env

Old `.env` approach:
```env
B2_APPLICATION_KEY_ID=key123
B2_APPLICATION_KEY=secret456
B2_BUCKET_NAME=mybucket
```

New `config.json` approach:
```json
{
  "b2": {
    "application_key_id": "key123",
    "application_key": "secret456",
    "bucket_name": "mybucket"
  }
}
```

## Quick Start

1. **Run setup**: `python setup.py`
2. **Configure**: `python config_util.py set`
3. **Test**: `python test_b2.py`
4. **Run**: `python app.py`

## Security Considerations

- `config.json` is excluded from git by default
- Sensitive data can be hidden in display utilities
- Environment variable fallback for production deployments
- Configuration validation prevents common mistakes
