# Network Contentstore Access Setup

## Problem
Your API server (Linux) needs to access files on the Aumentum server (Windows 10.10.10.3).

Current path: `D:\LRS_STORAGE\contentstore` (only accessible on Windows)

## Solution Options

### Option 1: Mount Windows Share via SMB/CIFS (Recommended)

#### Step 1: Install CIFS utilities on Linux
```bash
sudo apt-get update
sudo apt-get install -y cifs-utils
```

#### Step 2: Create mount point
```bash
sudo mkdir -p /mnt/aumentum_contentstore
```

#### Step 3: Create credentials file
```bash
sudo nano /root/.smb_credentials_aumentum
```

Add these lines:
```
username=Administrator
password=YOUR_WINDOWS_PASSWORD
domain=WORKGROUP
```

Secure the file:
```bash
sudo chmod 600 /root/.smb_credentials_aumentum
```

#### Step 4: Mount the share
```bash
# Test mount first
sudo mount -t cifs \
  //10.10.10.3/LRS_STORAGE \
  /mnt/aumentum_contentstore \
  -o credentials=/root/.smb_credentials_aumentum,uid=$(id -u),gid=$(id -g),file_mode=0755,dir_mode=0755
```

#### Step 5: Verify the mount
```bash
# Check if mounted
df -h | grep aumentum

# List contentstore
ls -la /mnt/aumentum_contentstore/contentstore/

# Test a specific file
ls -la /mnt/aumentum_contentstore/contentstore/2014/12/18/16/20/
```

#### Step 6: Make it permanent (auto-mount on boot)
```bash
sudo nano /etc/fstab
```

Add this line:
```
//10.10.10.3/LRS_STORAGE /mnt/aumentum_contentstore cifs credentials=/root/.smb_credentials_aumentum,uid=1000,gid=1000,file_mode=0755,dir_mode=0755 0 0
```

#### Step 7: Update Python configuration
Edit `aumentum_browser_service.py`:

```python
# OLD - Windows path (doesn't work from Linux)
DEFAULT_CONTENTSTORE_BASE = r"D:\LRS_STORAGE\contentstore"

# NEW - Linux mount point
DEFAULT_CONTENTSTORE_BASE = "/mnt/aumentum_contentstore/contentstore"
```

#### Step 8: Restart API server
```bash
# Kill existing server
pkill -f multipage_pdf_api.py

# Start new server
python3 multipage_pdf_api.py
```

---

### Option 2: NFS Share (Alternative)

If you prefer NFS instead of SMB:

#### On Windows (10.10.10.3):
1. Enable NFS Server feature
2. Share `D:\LRS_STORAGE` via NFS

#### On Linux API Server:
```bash
# Install NFS client
sudo apt-get install -y nfs-common

# Create mount point
sudo mkdir -p /mnt/aumentum_contentstore

# Mount
sudo mount -t nfs 10.10.10.3:/LRS_STORAGE /mnt/aumentum_contentstore

# Make permanent
echo "10.10.10.3:/LRS_STORAGE /mnt/aumentum_contentstore nfs defaults 0 0" | sudo tee -a /etc/fstab
```

---

### Option 3: Environment Variable Configuration

Use environment variable for flexibility:

```bash
# Set environment variable
export CONTENTSTORE_BASE="/mnt/aumentum_contentstore/contentstore"

# Or add to systemd service file
sudo nano /etc/systemd/system/aumentum-api.service
```

Service file content:
```ini
[Unit]
Description=Aumentum Browser API
After=network.target

[Service]
Type=simple
User=yourusername
WorkingDirectory=/path/to/your/app
Environment="CONTENTSTORE_BASE=/mnt/aumentum_contentstore/contentstore"
ExecStart=/usr/bin/python3 multipage_pdf_api.py
Restart=always

[Install]
WantedBy=multi-user.target
```

Then update `aumentum_browser_service.py`:
```python
import os

# Use environment variable with fallback
DEFAULT_CONTENTSTORE_BASE = os.getenv(
    "CONTENTSTORE_BASE",
    "/mnt/aumentum_contentstore/contentstore"
)
```

---

## Troubleshooting

### Mount fails
```bash
# Test network connectivity
ping 10.10.10.3

# Test SMB port
telnet 10.10.10.3 445

# Check Windows firewall
# On Windows: Allow "File and Printer Sharing"

# Check share name
# On Windows: Run `net share` to list shares
```

### Permission denied
```bash
# Check mount options
mount | grep aumentum

# Try mounting with different user
sudo mount -t cifs //10.10.10.3/LRS_STORAGE /mnt/aumentum_contentstore \
  -o username=Administrator,password=YOURPASS,uid=$(id -u),gid=$(id -g)
```

### Files not found after mounting
```bash
# Verify mount point has content
ls -la /mnt/aumentum_contentstore/

# Check subdirectories
find /mnt/aumentum_contentstore/contentstore -type d | head -20

# Test specific file from error message
ls -la /mnt/aumentum_contentstore/contentstore/2014/12/18/16/20/
```

### Path still shows Windows format
Check your configuration:
```bash
# Print current config
python3 -c "from aumentum_browser_service import DEFAULT_CONTENTSTORE_BASE; print(DEFAULT_CONTENTSTORE_BASE)"

# Should output: /mnt/aumentum_contentstore/contentstore
# NOT: D:\LRS_STORAGE\contentstore
```

---

## Quick Test After Setup

```bash
# 1. Check mount
df -h | grep aumentum

# 2. Test file access
TEST_FILE="/mnt/aumentum_contentstore/contentstore/2014/12/18/16/20/e03a480a-f6ef-477f-b453-0d9d094dac16.bin"
if [ -f "$TEST_FILE" ]; then
    echo "✓ File accessible"
    ls -lh "$TEST_FILE"
else
    echo "✗ File not found"
    # Show what's in the directory
    ls -la "$(dirname "$TEST_FILE")"
fi

# 3. Restart API and test
python3 multipage_pdf_api.py &
sleep 2
curl "http://localhost:8001/documents/id/10000000002503/pdf" -o test.pdf

# 4. Check if PDF was created
if [ -f test.pdf ]; then
    echo "✓ PDF generated successfully"
    file test.pdf
else
    echo "✗ PDF generation failed"
fi
```

---

## Windows Share Setup (If Not Already Shared)

On Windows server (10.10.10.3):

1. **Right-click** `D:\LRS_STORAGE` → **Properties**
2. **Sharing** tab → **Advanced Sharing**
3. ✓ **Share this folder**
4. Share name: `LRS_STORAGE`
5. **Permissions** → Add **Everyone** with **Read** access
6. **OK** to save

Or via PowerShell (as Administrator):
```powershell
# Create share
New-SmbShare -Name "LRS_STORAGE" -Path "D:\LRS_STORAGE" -ReadAccess "Everyone"

# Verify share
Get-SmbShare -Name "LRS_STORAGE"
```