# FastDesk NAS - Quick Start Guide

## What You Have

✅ **Backend Server** (`server.js`)  
✅ **SQLite Schema** (`fastdesk-schema.sql`)  
✅ **Import Tool** (`import.py`) - For your CSV exports  
✅ **Media Migration** (`migrate_media.py`) - Phase 2, optional  

---

## Phase 1: Setup & Import Data (15 mins)

### Step 1: Install Node Dependencies

```bash
npm install express sqlite3 bcrypt jsonwebtoken multer uuid
```

### Step 2: Initialize Database

```bash
sqlite3 fastdesk.db < fastdesk-schema.sql
```

### Step 3: Import Your CSV Data

```bash
python3 import.py links-export-2026-04-03_12-59-41.csv items-export-2026-04-03_12-38-57.csv --db fastdesk.db
```

You'll see:
```
🚀 FastDesk Import Tool
=====================================
👤 Creating default user (admin/password)...
   ✅ Default user created (CHANGE PASSWORD IMMEDIATELY)

📥 Importing from links-export-2026-04-03_12-59-41.csv...
   ✅ Cards imported: 7792
   ⏭️  Cards skipped: 0
   ✅ Keywords inserted: 58000+

📥 Importing from items-export-2026-04-03_12-38-57.csv...
   ✅ Items imported: 26978
   ⏭️  Items skipped: 0
   📸 Media references tracked: 5000+

📊 Final Stats:
   Active cards: 7792
   Total items: 26978
   Database: fastdesk.db
```

### Step 4: Start Backend Server

```bash
node server.js
```

Server runs on **port 3001** (or `$PORT` if you set it)

---

## Phase 2: Test & Deploy (optional)

### Test Login (curl)

```bash
curl -X POST http://localhost:3001/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"password"}'

# Response:
# {"token":"eyJhbGciOiJIUzI1NiIs...","user":{"id":"...","username":"admin"}}
```

### Get Cards (with token)

```bash
curl http://localhost:3001/api/cards \
  -H "Authorization: Bearer <your-token>"
```

---

## Phase 3: Media Migration (when ready)

Your media is **still in Supabase** — safe and working. When you want to move it to NAS:

```bash
python3 migrate_media.py --db fastdesk.db --media-dir ./media --limit 10
```

This will:
- Download 10 files from Supabase to NAS
- Update database with local paths
- Let you test before migrating all media

---

## Synology NAS Deployment

### Copy Files to NAS

```bash
scp -r ./* admin@<NAS-IP>:/volume1/docker/fastdesk/
```

### SSH into NAS

```bash
ssh admin@<NAS-IP>
cd /volume1/docker/fastdesk/
```

### Run with Docker (optional)

Use the `docker-compose.yml` from the earlier build:

```bash
docker-compose up -d
```

Access: `http://<NAS-IP>:3000`

---

## Important Notes

### ⚠️ CHANGE DEFAULT PASSWORD IMMEDIATELY

```bash
# Connect with default admin/password
# Then update your password through the app or:
sqlite3 fastdesk.db
UPDATE users SET password_hash = '<new-bcrypt-hash>' WHERE username = 'admin';
```

### 📸 Media Strategy (Phase 1)

- All media `media_url` fields still point to **Supabase**
- No download risk
- Full access via web (if you have internet)
- Migration is **completely optional**

### 🔐 Production Setup

Set environment variables:

```bash
export JWT_SECRET="your-super-secret-key-here"
export DB_PATH="/volume1/docker/fastdesk/data/fastdesk.db"
export MEDIA_PATH="/volume1/docker/fastdesk/data/media"
export PORT=3001

node server.js
```

---

## Files Created

| File | Purpose |
|------|---------|
| `fastdesk-schema.sql` | SQLite schema (cards, items, keywords, media) |
| `import.py` | CSV import tool (7,792 cards + 26,978 items) |
| `migrate_media.py` | Phase 2 media downloader |
| `server.js` | Express backend (auth, CRUD, search, upload) |
| `QUICKSTART.md` | This file |

---

## API Endpoints

```
POST   /api/auth/login              - Login (returns JWT token)
POST   /api/auth/register           - Register new user
GET    /api/cards                   - List cards (search, filter, paginate)
GET    /api/cards/:id               - Get single card + items + keywords
POST   /api/cards                   - Create card
PUT    /api/cards/:id               - Update card
DELETE /api/cards/:id               - Delete card
POST   /api/items                   - Create item
PUT    /api/items/:id               - Update item
DELETE /api/items/:id               - Delete item
GET    /api/search                  - Full-text search (q, type, keyword, cardId)
POST   /api/upload                  - Upload media file
GET    /api/media/:id               - Download media file
GET    /api/health                  - Health check
```

---

## Next Steps

1. ✅ Run `import.py` → Get data into SQLite
2. ✅ Start backend → `node server.js`
3. ⏭️ Build React frontend (coming next)
4. ⏭️ Deploy to NAS with Docker
5. ⏭️ (Optional) Migrate media in Phase 2

---

**Questions?** Check `/mnt/transcripts/2026-04-04-11-59-10-fastdesk-nas-build.txt` for full conversation context.
