# PrepVault — Google Drive Setup Guide

This guide walks you through connecting PrepVault's file library to your Google Drive folder. The process takes about 10–15 minutes and is free.

---

## Overview

PrepVault reads files from a **public Google Drive folder** using the Google Drive API v3. It only ever _reads_ files — it never writes, modifies, or deletes anything in your Drive.

You need two things:
1. A **Google API Key** (restricts usage to your domain)
2. Your **Drive Folder ID** (the folder PrepVault reads from)

---

## Step 1 — Create a Google Cloud Project

1. Go to [https://console.cloud.google.com/](https://console.cloud.google.com/)
2. Sign in with your Google account
3. Click the project dropdown at the top of the page (it may say "Select a project")
4. Click **NEW PROJECT**
5. Name it something like `PrepVault` and click **CREATE**
6. Wait a few seconds, then click **SELECT PROJECT** in the notification that appears

---

## Step 2 — Enable the Google Drive API

1. In the left sidebar, navigate to **APIs & Services → Library**
2. In the search box, type `Google Drive API`
3. Click **Google Drive API** in the results
4. Click the blue **ENABLE** button
5. Wait for it to enable — you'll be redirected to the API overview page

---

## Step 3 — Create an API Key

1. In the left sidebar, navigate to **APIs & Services → Credentials**
2. Click **+ CREATE CREDENTIALS** at the top
3. Select **API key**
4. Your new key will appear — **copy it** and keep it somewhere safe temporarily
5. Click **RESTRICT KEY** (or **Edit API key** if the dialog closed)

### Restrict the API Key (important!)

Restricting your key prevents unauthorized use:

**Application restrictions:**
- Select **HTTP referrers (websites)**
- Under "Website restrictions", click **ADD AN ITEM**
- Add your production domain: `https://yourdomain.com/*`
- If testing locally: also add `http://localhost/*` and `http://127.0.0.1/*`
- If using Netlify preview: add `https://*.netlify.app/*`

**API restrictions:**
- Select **Restrict key**
- In the dropdown, check **Google Drive API**
- Click **OK**

6. Click **SAVE**

> **Note:** It can take up to 5 minutes for restrictions to propagate. The key works immediately for testing.

---

## Step 4 — Create Your Drive Folder

1. Go to [https://drive.google.com/](https://drive.google.com/)
2. Click **+ New → Folder**
3. Name it something descriptive, like `PrepVault Library` or `Emergency Binder`
4. Click **CREATE**

### Name Your Files Correctly

PrepVault auto-categorizes files based on their names. Use these naming conventions for best results:

| Category | Keywords to include in filename |
|---|---|
| 🩺 First Aid | `first-aid`, `cpr`, `trauma`, `bleed`, `burn`, `wound` |
| 🌲 Survival Skills | `survival`, `fire`, `shelter`, `navigation`, `foraging` |
| 🌊 Natural Disasters | `hurricane`, `earthquake`, `tornado`, `flood`, `wildfire` |
| 💧 Food & Water | `water`, `food`, `purification`, `storage`, `ration` |
| 🏠 Shelter | `shelter`, `bug-out`, `evacuation`, `camp`, `tent` |
| 📻 Communication | `radio`, `ham`, `comms`, `signal`, `emergency-contact` |
| 💊 Medical | `medical`, `medication`, `prescription`, `dental`, `allergy` |
| 🔒 Security | `security`, `firearm`, `opsec`, `self-defense`, `lock` |
| ⚡ Off-Grid | `solar`, `generator`, `battery`, `off-grid`, `power` |
| 👨‍👩‍👧 Kids & Family | `kids`, `children`, `family`, `baby`, `school` |
| ♿ Disability Access | `accessibility`, `disability`, `mobility`, `wheelchair` |
| 🌐 Multilingual | `spanish`, `français`, `chinese`, `arabic`, `tagalog` |
| 🚗 Vehicle | `vehicle`, `car`, `truck`, `tire`, `roadside` |
| ✈️ Travel | `travel`, `passport`, `international`, `embassy` |
| 🏘️ Neighborhood | `neighborhood`, `community`, `HOA`, `mutual-aid` |

**Version tags** (optional): Add `v2`, `v3`, `2025`, `2026` to filenames to display version badges.

**Example filenames:**
```
first-aid-manual-v3-2025.pdf
hurricane-evacuation-checklist.pdf
water-purification-guide.pdf
family-emergency-plan-2025.pdf
medication-list-v2.pdf
```

---

## Step 5 — Make the Folder Public

> PrepVault needs public read access to list and link your files. Files remain viewable only to people with the link — your folder won't appear in Google search results.

1. Right-click your PrepVault folder in Google Drive
2. Click **Share**
3. Under "General access", click the dropdown (it likely says "Restricted")
4. Select **Anyone with the link**
5. Make sure the permission is set to **Viewer** (not Editor)
6. Click **Copy link** (you'll need this to extract the Folder ID)
7. Click **Done**

---

## Step 6 — Find Your Folder ID

Your Folder ID is in the URL when you open the folder:

```
https://drive.google.com/drive/folders/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                        This is your Folder ID
```

**To get it:**
1. Open your PrepVault folder in Google Drive
2. Look at the URL in your browser's address bar
3. Copy the long string of characters after `/folders/`

The Folder ID is typically 28–44 characters of letters, numbers, underscores, and hyphens.

---

## Step 7 — Configure PrepVault

1. Open PrepVault in your browser (your live site or `index.html` locally)
2. Click the **⚙ gear icon** in the top-right corner of the header
3. In the Settings modal:
   - Paste your **API Key** into the "Google Drive API Key" field
   - Paste your **Folder ID** into the "Drive Folder ID" field
   - Optionally set the **Auto-refresh interval** (default: 60 minutes)
4. Click **Save Settings**
5. Click **Test Connection** to verify everything works

If the connection succeeds, the status badge in the header will turn green and your files will appear in the grid.

---

## Troubleshooting

### "API key not valid" error
- Make sure you copied the entire API key (they're typically ~39 characters)
- Check that Google Drive API is enabled for your project (Step 2)
- Verify the API key has "Google Drive API" in its API restrictions (Step 3)
- If you just created or modified restrictions, wait 5 minutes and try again

### "Folder not found" or 404 error
- Confirm the folder is set to "Anyone with the link" (Step 5)
- Double-check you copied the full Folder ID with no extra characters
- Try opening `https://www.googleapis.com/drive/v3/files?q='YOUR_FOLDER_ID'+in+parents&key=YOUR_API_KEY` in a browser — if you get JSON back, it's working

### "Access denied" or 403 error
- Your API key's HTTP referrer restrictions don't match your current URL
- When testing locally, ensure `http://localhost/*` is in the allowed referrers
- For GitHub Pages, add `https://YOURUSERNAME.github.io/*`

### No files appear after connecting
- Make sure there are actual files (not just subfolders) directly in the folder
- PrepVault only reads files in the top-level of the specified folder
- Check that each file's sharing is set to at least "Anyone with the link can view"

### Files show but won't download/open
- Google Drive individual file permissions may be set to "Restricted"
- Select files in Drive → right-click → Share → set to "Anyone with the link"
- Alternatively, use "Get link" on each file you want publicly accessible

---

## Refreshing Your Library

PrepVault caches your file list in the browser's `localStorage` for up to 24 hours to support offline use. To force an immediate refresh:

- Click **⚙ Settings → Test Connection** (always fetches fresh)
- Or clear the PrepVault cache: open browser DevTools → Application → Local Storage → delete `prepvault-drive-cache`

Auto-refresh runs silently in the background based on your configured interval.

---

## Privacy & Security

- Your API key and Folder ID are stored **only in your browser's localStorage** — they never leave your device except to make API calls directly to Google's servers
- PrepVault makes **read-only** requests — it cannot modify, delete, or upload files
- Google Drive API calls are logged by Google per their standard policies
- You can revoke the API key at any time in Google Cloud Console → Credentials
- To clear all PrepVault data: Settings → scroll to bottom → "Reset All Settings"

---

## API Quotas

Google Drive API has generous free quotas:
- **10,000 requests/day** (shared across all users of your key)
- **1,000 requests/100 seconds** per user

For a personal PrepVault site with reasonable traffic, you will not hit these limits. If you share PrepVault publicly at scale, consider adding a caching layer or requesting a quota increase in Google Cloud Console.
