DLRSDLRS
Integrations

Google Drive — Index Once, Find Everywhere

Connect Drive to auto-index filenames, folders, and file contents. Ask “latest logo” from anywhere and get it instantly — beginner-friendly with technical depth.

What Drive Integration Does

Beginner: Why Index?

Without indexing, you'd browse 5 folders deep to find GB-logo-final.png. With indexing, DLRS knows: file in GB-Banquet/Assets, linked to client GB, contains logo, last modified 2025-12-01. Search finds it in one query across Drive + Tasks + Emails.
  • Indexes metadata: name, folder path, mime, size, modified time
  • Extracts content: text from Docs/Sheets/PDFs via export
  • Links to clients/projects: name heuristics
  • Powers Context Pack: task “GB reel” auto-shows Drive folder link

OAuth Setup

Google Cloud — Same as Gmail

Enable Drive API. Use same or separate OAuth credentials. Redirect:

http://localhost:3000/api/integrations/drive/callback

.env

GOOGLE_DRIVE_CLIENT_ID="..."
GOOGLE_DRIVE_CLIENT_SECRET="..."
SECRET_ENCRYPTION_KEY="..."

Connect

Settings → Integrations → Drive → Connect → consent (read-only scope .../auth/drive.readonly) → token encrypted in vault.

Indexing — How Files Get Found

Trigger: manual POST /api/integrations/drive/sync or job weekly

Job: drive_index
Steps:
1. Decrypt token transiently
2. List files via Drive API (files.list, pageSize 100, trashed=false)
3. For each file:
   - files { id, workspace_id, name, mime, folder_path, drive_id, parent_id, size, modified_at }
   - If mime is Google Doc/Sheet/Slide/PDF → export to text (via Drive export)
   - Store text in documents.content_text
4. Index for search: lib/search indexing (keyword now, vector later)

Code: lib/integrations/drive/sync.ts
  • All non-trashed files you have access to
  • Google Docs/Sheets/Slides → exported as text
  • PDFs → via unpdf extraction
  • Images with text → OCR if possible

Linking to Clients/Projects

Heuristics in lib/integrations/drive/link.ts:
- File name contains client name: "GB-logo.png" → client_id = GB Banquet
- Folder path contains project: "/GB-Banquet/Assets" → project_id = GB Banquet Assets
- Content mentions client: Doc says "For GB Banquet event"

Result: files.linked_client_id, linked_project_id
Used in Context Pack: task for GB → shows linked files automatically

Search Example

User query: "Find Tanniaqua product spec"
→ Search Agent:
   Drive: Tanniaqua-Product-Spec.pdf (score 0.95, path /TanniaquaZone/Product/)
   Tasks: "Update product post" (0.72)
   Emails: Sarah email mentioning spec (0.68)

Ranking: exact name match > folder path > content mention > recency

Returns: file card with [Open Drive] + [Preview] + provenance

Storage & Database

Tables:
files {
  id, workspace_id, name, mime, size, storage_path, drive_id,
  folder_path, parent_id, linked_client_id, linked_project_id, modified_at
}
documents {
  id, workspace_id, file_id, title, content_text, summary, extracted_json
}

Keywords: drive_id (Google's ID), folder_path ("/GB/Assets"), linked_* (graph edges)

Storage: Drive files not duplicated locally (only metadata); uploaded files stored in STORAGE_DIR

On this page