Skip to content

feat: add Google Drive backend module - #243

Merged
hesprs merged 8 commits into
hesprs:mainfrom
Quzzar:gdrive-module
Aug 23, 2026
Merged

feat: add Google Drive backend module#243
hesprs merged 8 commits into
hesprs:mainfrom
Quzzar:gdrive-module

Conversation

@Quzzar

@Quzzar Quzzar commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What

A new gdrive module adding Google Drive as a sync backend, following the module contribution guide (package under packages/, modules.json entry, spec page in deep-dive/modules/, sidebar + i18n entries).

Design

  • Auth: Google OAuth device flow against the user's own OAuth client ("TV and Limited Input devices" type), so no hosted bridge or third-party server is involved. Scope is drive.file + email — the module can only see files it created. The client secret and refresh token live in Obsidian secret storage; a remote request middleware injects the bearer token, refreshes it before expiry (deduped across concurrent callers), and retries once on 401 — same pattern as the S3 module's SigV4 middleware.
  • File system: GdriveFs implements RootFs with a per-instance path→id cache. Folders are real Drive folders; move() uses native re-parenting; deletes go to the Drive trash by default (setting to disable); md5Checksum is the uid; the local mtime is written to Drive's modifiedTime so timestamps round-trip.
  • Listing: since drive.file only exposes module-created files, list() fetches all visible files in one paginated query and assembles the tree client-side, honoring reporter verdicts (advance/include/exclude) without visiting excluded subtrees.
  • Uploads: multipart for small files, sequential resumable sessions (8 MiB chunks) for large ones; ranged-GET read streaming mirrors the S3 read stream.

Tests

An in-memory Drive API v3 mock (test/mock-drive.ts) covers lookup/list queries, ranged media downloads, multipart + resumable uploads, patches, and deletes. 23 tests exercise the full RootFs contract plus the device flow, token manager, and bearer middleware. bun check and bun tests pass across the workspace.

Notes for review

  • The modules.json entry points at https://sync.consensia.cc/modules/gdrive.js following the existing convention — hosting is yours to wire up at release time.
  • The docs sidebar's existing smart-merge entry has two pre-existing typos (lint: instead of link:, smart-marge) — left untouched to keep this PR scoped, happy to fix in a follow-up.
  • Per the contributing guide's AI-contribution section: this module was written with an AI agent, reviewed and tested end-to-end; I'm responsible for follow-ups.

Fixes

Resolves #245

@hesprs

hesprs commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Wow this is amazing. It could take me a while to review.

Adds a gdrive module implementing the RootFs contract against the
Google Drive API v3 with the drive.file scope. Authentication uses
Google's OAuth device flow against the user's own OAuth client, with
tokens in Obsidian secret storage and a bearer-token request
middleware that refreshes and retries once on 401. Listing fetches
all visible files in one paginated query and assembles the tree
client-side; uploads use multipart for small files and sequential
resumable sessions for large ones; deletes go to the Drive trash by
default. Includes an in-memory Drive API mock and contract tests,
a module spec page, and registry plus docs sidebar entries.
@hesprs

hesprs commented Aug 22, 2026

Copy link
Copy Markdown
Owner

The auth can work but is nearly wrong, Fable conflated a lot of stuff. And the code is unnecessarily verbose.

@hesprs
hesprs merged commit 9e98418 into hesprs:main Aug 23, 2026
1 check passed
@hesprs

hesprs commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Thanks for contribution. Now the Google Drive backend works like a charm.

I have registered a Google App in Google Developer console, so that users don't need to register themselves (which is very complicated). The registration is being reviewed by Google, after that, the module will be publicly installable in the module catalog.

If you want to test in advance, please provide your Google Account email so that I can grant you tester role and send you the compiled module binary.


Unexpectedly, the review passes instantly. So you can try it now.

@hesprs hesprs mentioned this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sync error after file renaming

2 participants