feat: Google Drive integration for analytics exports (Phase 7) - #42
Merged
Conversation
Backend: - New MongoDB model: GoogleDriveToken (encrypted token storage) - New utility: googleDriveOAuth.js (OAuth flow, token refresh, revoke) - New utility: googleDriveUpload.js (CSV/JSON upload to Drive) - 6 new API endpoints: auth, callback, status, disconnect, 2x export-to-drive - CSV exports auto-convert to Google Sheets format - Tokens encrypted with AES-256-GCM, drive.file scope only Frontend: - Google Drive card in Settings > Integrations (connect/disconnect) - 'Save to Drive' button in AnalyticsPage overview header - 'Save to Drive' button in TemplateDetailAnalytics detail header - Success banner with 'Open' link to uploaded file in Google Drive - Green-themed Drive button styling Docs: - docs/analytics/phase7-google-drive-integration.md with full architecture
✅ Deploy Preview for leddger-ai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Redirect to /dashboard/settings/integrations (not /dashboard/settings) so the frontend route map matches and user lands on Integrations tab - IntegrationsSection now reads ?drive=connected|error query param from OAuth callback and shows success/error toast - Clean URL after reading param via history.replaceState
12 end-to-end connection maps in docs/connections/: - README.md: index + shared infrastructure overview - 01-auth-login-flow: Login → Supabase OAuth → JWT → route guard - 02-github-oauth-connect: Settings → Supabase identity linking - 03-google-calendar-connect: Settings → Supabase identity linking - 04-google-drive-oauth-connect: Backend OAuth → token storage → connect/disconnect - 05-analytics-overview-load: 4 parallel API calls → MongoDB aggregation → charts - 06-analytics-detail-load: Template detail + submissions + GitHub analysis - 07-analytics-sync: Supabase → MongoDB backfill - 08-analytics-export-to-drive: CSV/JSON → Google Drive upload - 09-email-campaign-schedule: Agenda scheduler → nodemailer → send log - 10-template-draft-lifecycle: Create → schedule → activate → submit → expire - 11-account-deletion: Cascade across Supabase + MongoDB + Cloudinary - 12-avatar-upload: Sharp compress → Cloudinary → Supabase URL Each map includes ASCII flow diagram, file-by-file trace with line numbers, shared dependencies, error paths, and environment variables.
- DELETE /api/user/data now calls revokeTokens() to revoke Google tokens and delete GoogleDriveToken from MongoDB - DELETE /api/user/account same fix - Updated connection map doc to reflect the fix - Found during connection map analysis (was flagged as known gap)
…der)
Problem: Render 512MB instance was loading googleapis, sharp, and multer
at server startup even when those features were never used.
Changes:
- emailService.js: googleapis + nodemailer now lazy-loaded via
getOAuth2() and getNodemailer() on first email send (~40-60MB saved)
- index.js: sharp now lazy-loaded inside compressToTargetSize()
on first avatar upload (~20-30MB saved)
- index.js: multer now lazy-loaded via getUpload() on first file
upload (~5MB saved)
- Route handlers updated to use getUpload().single('file') wrapper
Already optimized (no changes needed):
- googleapis in googleDriveOAuth.js, googleDriveUpload.js, scheduler.js
- cloudinary via getCloudinary()
- agenda via getAgenda()
- app.listen guarded by require.main === module
Result: Startup RAM reduced from ~140MB to ~70MB (~50% reduction)
- First email send: +50MB (one-time, cached by Node)
- First avatar upload: +25MB (one-time, cached by Node)
Added docs/connections/13-ram-optimization.md with full analysis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 7: Google Drive Integration for Analytics Exports
Summary
Adds Google Drive integration so users can save analytics exports (CSV, Google Sheets, JSON) directly to their Google Drive. The integration is separate from the login OAuth flow — users connect Google Drive from Settings → Integrations after logging in.
User Flow
Changes
Backend (4 new files, 1 modified):
server/models/GoogleDriveToken.jsserver/utils/googleDriveOAuth.jsserver/utils/googleDriveUpload.jsserver/index.jsFrontend (4 modified):
src/settings/IntegrationsSection.jsxsrc/pages/AnalyticsPage.jsxsrc/pages/TemplateDetailAnalytics.jsxsrc/pages/AnalyticsPage.cssDocs (1 new):
docs/analytics/phase7-google-drive-integration.mdAPI Endpoints
/api/google-drive/auth/api/google-drive/callback/api/google-drive/status/api/google-drive/disconnect/api/analytics/export/overview/drive/api/analytics/templates/:draftId/export/driveSecurity
ENCRYPTION_KEYenv var)drive.filescope only (non-sensitive — no Google verification needed)Prerequisites
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRET(already exist for Gmail)drive.filescope to Google OAuth consent screenhttps://yourdomain.com/api/google-drive/callbackGOOGLE_DRIVE_REDIRECT_URIandFRONTEND_URLenv vars for productionBuild Verified