Repository navigation
Add Google Drive integration for automated DB backups - #138
Merged
Merged
Conversation
Adds an opt-in Google Drive connection under Settings > Integrations, following the same explicit opt-in shape as the existing Cloud Services tab: nothing talks to Google until the owner clicks Connect. - OAuth "installed app" loopback flow (system browser + local redirect server on a random port), scoped to drive.file only, using the googleapis package. Client credentials come from GOOGLE_DRIVE_CLIENT_ID/GOOGLE_DRIVE_CLIENT_SECRET env vars; when unset, Settings shows "Google Drive integration is not configured for this build" instead of a broken Connect button. - Tokens are encrypted at rest via Electron's safeStorage (same pattern as master-pin.ts) in their own file, never in the SQLite DB. Disconnecting revokes the token with Google's /revoke endpoint before deleting the local blob. - Reuses createBackup() from db.ts unchanged for the uploaded artifact — no second export path. Configurable daily/weekly schedule (hourly check, same cadence as telemetry) plus a manual "Back up to Drive now" action, both funneled through the same upload/retention code path. - Retention: keeps the last N backups (default 10) in a dedicated Drive folder, deleting the oldest beyond that after each successful upload. - Backup History table (#120) shows a "Synced to Drive" badge on the local backup that was last uploaded. - docs/google-drive-setup.md documents the exact Google Cloud Console steps a maintainer must follow to create the OAuth client. New dependency: googleapis (bundles its own google-auth-library, used via google.auth.OAuth2 to avoid a duplicate-version type conflict with a standalone google-auth-library install). Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
Summary
Adds optional Google Drive integration so database backups can be automatically uploaded off-device on a schedule, on top of the local
backups/folder and the Backup Management & History UI from #120.Follows the same explicit opt-in shape as the existing Cloud Services tab (see the offline-first audit): nothing in this PR talks to Google until the store owner explicitly clicks "Connect" in Settings > Integrations > Google Drive.
shell.openExternaland catches the redirect on a local HTTP server bound to a random port, rather than an embedded webview. Scope isdrive.fileonly (the app only ever sees files it creates). Built with thegoogleapispackage (its bundledgoogle.auth.OAuth2, to avoid a duplicate-version type conflict with installing the standalonegoogle-auth-librarypackage alongside it).GOOGLE_DRIVE_CLIENT_ID/GOOGLE_DRIVE_CLIENT_SECRETenvironment variables (same pattern as the existingJWT_SECRET). If either is unset, Settings shows "Google Drive integration is not configured for this build" instead of a broken Connect button — no crash, no dead-end UI.safeStorage(identical pattern tomain/services/master-pin.ts), in their own file (google-drive-token.enc) — never in the SQLite DB. Disconnecting revokes the token via Google's/revokeendpoint (not just clearing local UI state) before deleting the encrypted blob locally, and does so resiliently even if Google is unreachable.createBackup()frommain/db.tsunmodified — no second export path that could skip the existing/api/db/exportsecret-redaction. Configurable daily/weekly schedule (hourly check timer, same cadence as the existing telemetry service) plus a manual "Back up to Drive now" button, both going through the same upload/retention path.database.tsgates the raw backup/restore actions); status + frequency/retention preferences are owner+manager, matching the Cloud tab.New dependency
googleapis(^173.0.0) — Drive API v3 client + OAuth2 client. (google-auth-librarywas evaluated but not added directly:googleapisbundles its own compatible copy, and installing both caused a TypeScript duplicate-declaration conflict between the two copies'OAuth2Clienttypes.)Maintainer setup required before this is usable
This integration ships disabled by default and needs real Google Cloud OAuth client credentials before "Connect" works in any build. I don't have a Google account / Cloud Console access in this environment, so I could not create real credentials — the full code path (loopback OAuth, token encryption, Drive upload, retention, revoke) is implemented and tested against the "not configured" and "configured but not yet connected" states, but the actual OAuth handshake against real Google infrastructure has not been exercised end-to-end.
A maintainer needs to:
docs/google-drive-setup.mdto create an OAuth client in Google Cloud Console (enable Drive API, configure the consent screen with thedrive.filescope, create a Desktop app OAuth client).GOOGLE_DRIVE_CLIENT_ID/GOOGLE_DRIVE_CLIENT_SECRETfor the build (see.env.example/ README "Environment Variables").Out of scope (per the issue)
Test plan
npm run build(backendtsc) — cleannpm --prefix frontend run build— cleannpm run lint(backend + frontend eslint) — 0 errors (pre-existing warnings elsewhere untouched; new files have 0 warnings)npm test— full existing suite passes, including a newtests/google-drive.test.tscovering config detection, retention/scheduling math, settings persistence + validation, and the encrypted-token file lifecycle (connect/disconnect's real OAuth network path isn't covered — see above)Closes #129