# Course Video Manager

A tool for managing course video publishing workflows — editing metadata, generating descriptions, creating thumbnails, and posting to social platforms.

## Database migrations

Schema changes are managed with **drizzle-kit generate / migrate** (versioned SQL files), not `push`.

### Making a schema change

1. Edit `app/db/schema.ts`.
2. `pnpm db:generate` — creates a new numbered `.sql` file under `app/db/migrations/`.
3. `pnpm db:migrate` — applies any pending migrations to the local database.

### First-time setup on an existing database

If the database was originally created via `drizzle-kit push` and has never run migrations:

```sh
pnpm db:baseline
```

This registers the `0000` baseline migration as already-applied so `db:migrate` won't replay the initial `CREATE TABLE` statements.

### Scripts

| Script             | Description                                          |
| ------------------ | ---------------------------------------------------- |
| `pnpm db:generate` | Generate a new migration from schema changes         |
| `pnpm db:migrate`  | Apply pending migrations to the database             |
| `pnpm db:baseline` | Mark the `0000` baseline as applied (one-time setup) |
| `pnpm db:studio`   | Open Drizzle Studio                                  |

## Zapier Webhook Setup (Buffer Integration)

The app uses a **Dropbox → Zapier → Buffer** pipeline to post videos to social media. When you click "Post to Buffer" in the app, it:

1. Copies the video file into a local Dropbox folder
2. Waits for Dropbox to sync the file to the cloud
3. Sends a webhook to Zapier with the caption and file path
4. Zapier finds the file in Dropbox and adds it to your Buffer queue

### Prerequisites

- **Dropbox desktop client** installed and running (the app uses `dropbox filestatus` to poll sync status)
- **Buffer account** connected in Zapier
- **Zapier account** with access to the Webhooks by Zapier and Buffer integrations

### Environment Variables

| Variable                    | Description                                                                                                                      |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `BUFFER_POSTS_PATH`         | Local path to a folder inside your Dropbox directory where video files are copied before posting (e.g. `~/Dropbox/buffer-posts`) |
| `ZAPIER_BUFFER_WEBHOOK_URL` | The webhook URL generated by your Zapier Zap (see below)                                                                         |
| `AI_HERO_BASE_URL`          | Base URL for the AI Hero instance (e.g. `https://www.aihero.dev`). Required for AI Hero posting integration.                     |

### Creating the Zapier Zap

#### Step 1: Create a "Webhooks by Zapier" trigger

1. Create a new Zap in Zapier
2. For the trigger, choose **Webhooks by Zapier**
3. Select **Catch Hook** as the trigger event
4. Copy the generated webhook URL
5. Set it as the `ZAPIER_BUFFER_WEBHOOK_URL` environment variable in your app

The webhook receives a JSON payload with this shape:

```json
{
  "caption": "Your post caption text",
  "dropboxFilePath": "/full/path/to/buffer-posts/video.mp4"
}
```

#### Step 2: Add a "Dropbox: Find File" action

1. Add an action step and choose **Dropbox**
2. Select **Find File** as the action event
3. Configure it to look up the file using the `dropboxFilePath` value from the webhook payload

#### Step 3: Add a "Buffer: Add to Queue" action

1. Add another action step and choose **Buffer**
2. Select **Add to Queue** as the action event
3. Map the **media** field to the Dropbox file URL from Step 2
4. Map the **text** field to the `caption` value from the webhook payload

#### Step 4: Test and enable

1. Use the app to trigger a test post so Zapier can capture a sample webhook payload
2. Walk through each step to verify the data mapping is correct
3. Turn on the Zap
