Add --as flag for Drive upload type override and fix trashed filtering#47
Merged
Merged
Conversation
- 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
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
This PR adds support for the
--asflag todrive 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 intodrive listanddrive searchresults.Key Changes
New
--asflag fordrive upload: Allows forcing the converted-to type (e.g.,--as sheet) to override extension inference. Accepts friendly aliases (doc,sheet,slides,drawing,form) or rawapplication/vnd.google-apps.*MIME types.Source MIME type declaration: Added
driveSourceMimeByExtmap anddriveMediaOption()function to explicitly declare the source content type during upload. This prevents Drive's import converter from content-sniffing files (e.g.,.csvastext/plaininstead oftext/csv), which was causing CSVs to be imported as Docs even when the target was a spreadsheet.Trashed items filtering:
drive listnow automatically addstrashed = falseto queries (unless the user explicitly mentionstrashedin their custom query)drive searchnow includestrashed = falsein its generated queryHelper function
resolveDriveTargetMime(): Validates and resolves--asvalues to native Google-apps MIME types, with proper error handling for invalid inputs.Updated function signatures:
uploadOneFile(),uploadTree(), andrunDriveUpload()now accept atargetMimeOverrideparameter to support the--asflag.Media upload improvements: Both
Files.CreateandFiles.Updateoperations 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.csvfile would be content-sniffed astext/plainand imported as a Doc even withapplication/vnd.google-apps.spreadsheetas the target.The
--asflag 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--asvalue resolution logicTestRunDriveUpload_ConvertCSVToSheet: Verifies CSV→Sheet conversion with proper source MIME typeTestRunDriveUpload_AsOverride: Verifies--asforces the target type without--converttargetMimeOverrideparameterhttps://claude.ai/code/session_01K3CYduZ3LYpiYPSuButL56