Skip to content

feat: add downloadFile tool for Google Drive#96

Merged
a-bonus merged 2 commits intoa-bonus:mainfrom
Mawox:feat/download-file
Mar 23, 2026
Merged

feat: add downloadFile tool for Google Drive#96
a-bonus merged 2 commits intoa-bonus:mainfrom
Mawox:feat/download-file

Conversation

@Mawox
Copy link
Copy Markdown

@Mawox Mawox commented Mar 23, 2026

Summary

  • downloadFile: Downloads any file from Google Drive to a local path. Auto-detects blob files vs Google Workspace files and handles each appropriately.
    • Blob files (PDFs, images, Excel, etc.): downloads raw bytes via files.get with alt: 'media'
    • Google Workspace files (Docs, Sheets, Slides): exports via files.export with text-friendly defaults (Docs -> markdown, Sheets -> CSV, Slides -> plain text)
    • Optional savePath: defaults to current working directory with appropriate filename/extension
    • Text extraction: returns up to 50KB of text content for text-based files alongside saving to disk
    • Stream safety: uses pipeline from node:stream/promises for proper error handling and partial file cleanup
    • Shared Drives: supportsAllDrives: true on all files.get calls

Files changed (3 files, 584 lines)

File Description
src/tools/drive/downloadFile.ts New tool implementation with exported constants and helpers
src/tools/drive/downloadFile.test.ts 32 Vitest tests (pure unit + mocked integration)
src/tools/drive/index.ts Registration of the new tool

Test plan

  • npm run build -- compiles cleanly
  • npm test -- all 172 tests pass (32 new + 140 existing)
  • npm run format -- Prettier applied
  • Pure unit tests: WORKSPACE_EXPORT_DEFAULTS values, EXPORT_MIME_TO_EXTENSION map, isTextMimeType boundary cases
  • Blob download: exact API params, supportsAllDrives, files.export NOT called
  • Workspace export: default MIME selection, custom override, files.get NOT called with alt:media
  • Text extraction: exact content, absent for binary, 50KB truncation, blob text files
  • Optional savePath: cwd defaults, correct extensions for exports
  • Error handling: partial file cleanup, unsupported Workspace types

Jon added 2 commits March 23, 2026 18:24
Downloads any file from Google Drive to a local path. For blob files (PDFs, images, etc.), downloads raw bytes. For Google Workspace files (Docs, Sheets, Slides), exports to a configurable format with text-friendly defaults (Docs->markdown, Sheets->CSV).

Features: optional savePath (defaults to cwd), automatic text extraction for text-based files (up to 50KB), parent directory auto-creation, partial file cleanup on error, Shared Drive support.

Includes 32 Vitest tests covering pure unit tests and mocked integration tests.

Made-with: Cursor
@a-bonus a-bonus merged commit 4e1f8f8 into a-bonus:main Mar 23, 2026
4 checks passed
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.

2 participants