Skip to content

Add --as flag for Drive upload type override and fix trashed filtering#47

Merged
wesnick merged 2 commits into
mainfrom
claude/fix-file-conversion-mappings-VO46U
May 18, 2026
Merged

Add --as flag for Drive upload type override and fix trashed filtering#47
wesnick merged 2 commits into
mainfrom
claude/fix-file-conversion-mappings-VO46U

Conversation

@wesnick

@wesnick wesnick commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds support for the --as flag to drive upload, allowing users to force a target Google Workspace type (doc, sheet, slides, etc.) without requiring --convert. It also fixes a critical issue where trashed items were leaking into drive list and drive search results.

Key Changes

  • New --as flag for drive upload: Allows forcing the converted-to type (e.g., --as sheet) to override extension inference. Accepts friendly aliases (doc, sheet, slides, drawing, form) or raw application/vnd.google-apps.* MIME types.

  • Source MIME type declaration: Added driveSourceMimeByExt map and driveMediaOption() function to explicitly declare the source content type during upload. This prevents Drive's import converter from content-sniffing files (e.g., .csv as text/plain instead of text/csv), which was causing CSVs to be imported as Docs even when the target was a spreadsheet.

  • Trashed items filtering:

    • drive list now automatically adds trashed = false to queries (unless the user explicitly mentions trashed in their custom query)
    • drive search now includes trashed = false in its generated query
    • This prevents trashed items from leaking into folder/search listings
  • Helper function resolveDriveTargetMime(): Validates and resolves --as values to native Google-apps MIME types, with proper error handling for invalid inputs.

  • Updated function signatures: uploadOneFile(), uploadTree(), and runDriveUpload() now accept a targetMimeOverride parameter to support the --as flag.

  • Media upload improvements: Both Files.Create and Files.Update operations now pass explicit media options to declare source content types.

Notable Implementation Details

  • The source MIME type is critical for Drive's import converter: it keys off the uploaded media's MIME type, not the target metadata mimeType. Without this, a .csv file would be content-sniffed as text/plain and imported as a Doc even with application/vnd.google-apps.spreadsheet as the target.

  • The --as flag implies conversion without requiring --convert, providing a more intuitive UX for users who want to force a specific type.

  • Trashed filtering respects user intent: if a custom query explicitly mentions trashed, the automatic filter is skipped, giving users full control when needed.

Tests Added

  • TestResolveDriveTargetMime: Validates the --as value resolution logic
  • TestRunDriveUpload_ConvertCSVToSheet: Verifies CSV→Sheet conversion with proper source MIME type
  • TestRunDriveUpload_AsOverride: Verifies --as forces the target type without --convert
  • Updated existing tests to pass the new targetMimeOverride parameter

https://claude.ai/code/session_01K3CYduZ3LYpiYPSuButL56

claude added 2 commits May 18, 2026 13:33
- Declare an explicit source content type by extension on upload media
  (driveSourceMimeByExt/driveMediaOption). Drive's import converter keys
  off the uploaded media's MIME, not the target metadata, so a .csv was
  content-sniffed as text/plain and imported as a Doc despite the
  google-apps.spreadsheet target. This is the root cause of --convert
  producing Docs for CSV/Sheets/Slides.
- Add `drive upload --as doc|sheet|slides|drawing|form` (or a raw
  application/vnd.google-apps.* type) to force the converted-to type,
  overriding extension inference and implying conversion.
- Default `drive list`/`drive search` to `trashed = false` so trashed
  children no longer leak into folder/search listings; an explicit
  `trashed` clause in --query still takes precedence.

https://claude.ai/code/session_01K3CYduZ3LYpiYPSuButL56
Mirror the drive upload conversion fix and the trashed=false default for
drive list/search into the agent-facing skill doc.

https://claude.ai/code/session_01K3CYduZ3LYpiYPSuButL56
@wesnick
wesnick merged commit 0d7fff7 into main May 18, 2026
1 check passed
@wesnick
wesnick deleted the claude/fix-file-conversion-mappings-VO46U branch May 18, 2026 14:11
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