fix(google_drive): support Google Workspace native file exports - #3137
Draft
mythic3011 wants to merge 6 commits into
Draft
mythic3011 wants to merge 6 commits into
mythic3011 wants to merge 6 commits into
Conversation
- Add FileMeta struct to capture mimeType and capabilities/canDownload
from the files.get metadata response already performed in Link()
- Add downloadStrategy / resolveDownloadStrategy to map source MIME
types to the correct Drive endpoint:
- Binary/uploaded files → files.get?alt=media&acknowledgeAbuse=true
- Google Docs/Sheets/Slides/Drawing/Script → files.export?mimeType=...
- Non-downloadable Workspace types (folder, shortcut, form, site, map,
vid, unknown) → explicit error instead of a misleading 403
- Add FileLinkFields constant for the fields param used in Link()
- Add MIME type constants and googleWorkspaceExports /
googleWorkspaceUnsupported maps for centralized, data-driven routing
- Fix pre-existing go vet warnings: non-constant format strings in
refreshToken()
- Add util_test.go covering strategy resolution for 21 cases:
media download, export, unsupported types, and URL query encoding
- Remove invalid params from files.export URL: drop includeItemsFromAllDrives and supportsAllDrives; export endpoint takes only mimeType - Extract buildDownloadURL() pure helper; use it from Link() - Remove dead Ext field from exportFormat and downloadStrategy; simplify googleWorkspaceExports to map[string]string - Replace manual MIME-prefix slice check with strings.HasPrefix - Reword unsupported-type errors to describe driver limitation rather than API impossibility (form, site, map, vid) - Add 10 MB export size cap comment near files.export path - Revert unrelated go vet cleanup in refreshToken() (fmt.Errorf format string; leave for a separate PR) - Replace TestExportURLEncoding with TestBuildDownloadURL; assert scheme, host, path, query values via net/url.Parse; verify export URLs exclude media-only params
- Remove includeItemsFromAllDrives from files.get media URL; it is a files.list parameter, not a files.get parameter; supportsAllDrives is preserved for shared-drive support - Remove blanket application/vnd.google-apps.* prefix rejection; unrecognised Drive MIME types now fall through to kindMedia to preserve compatibility with non-editor types such as application/vnd.google-apps.video / audio / photo - Remove now-unused strings import - Separate Google My Maps from the files.download LRO group; its unsupported reason is now implementation-neutral - Add TestResolveDownloadStrategy_MediaFallback covering video, audio, photo and unknown google-apps variants - Update TestBuildDownloadURL: assert includeItemsFromAllDrives is absent from media URL; remove stale assertion
application/vnd.google-apps.jam falls through to the media download path without this change, reproducing the fileNotDownloadable 403. Jamboard downloads require the files.download LRO flow, consistent with Vids.
- Add FileName field to model.Link for driver-supplied download filename override - Preserve FileName in Link.Clone() - Add linkFileName helper in proxy.go; use it in all Content-Disposition and ServeHTTP calls - Restore exportFormat struct with MIME and Extension fields in types.go - Change googleWorkspaceExports to map[string]exportFormat with per-type extensions - Add mimeTypeGoogleDriveSDK constant and unsupported entry - Add Extension field to downloadStrategy; populate from exportFormat in resolveDownloadStrategy - Add exportedFileName helper (case-insensitive suffix check to avoid double extensions) - Set link.FileName in Link() for kindExport strategies - Update TestResolveDownloadStrategy_Export to check Extension field - Add mimeTypeGoogleDriveSDK to TestResolveDownloadStrategy_Unsupported - Add TestExportedFileName covering CJK names, already-extended names, case-insensitive dedup - Add TestLinkFileName and TestProxyUsesLinkFileNameForContentDisposition
mythic3011
force-pushed
the
fix/google-drive-workspace-export
branch
from
September 24, 2026 19:40
4852081 to
d96708e
Compare
Replace googleWorkspaceUnsupported messages with consistent wording for LRO-only types, drive-sdk shortcuts, and My Maps.
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 / 摘要
Fix Google Drive downloads for Google Workspace-native files.
Previously, the Google Drive driver used
files.get?alt=mediafor all files. Google Drive only supports that download path for blob/binary files. Google Workspace-native files such as Docs, Sheets, and Slides must usefiles.export.This caused Workspace-native files to fail with:
This PR:
Fetches
mimeTypeandcapabilities.canDownloadinLink()before selecting the download path.Keeps blob/binary files on
files.get?alt=media.Routes supported Workspace-native files through
files.export.Adds centralized export mappings:
Returns explicit errors for known native types that are not supported by the current synchronous download path.
Preserves the existing media-download fallback for unrecognized Drive MIME types to avoid compatibility regressions.
Preserves existing file-shortcut behavior: shortcuts resolve to the target file ID before
Link()selects the download strategy.Adds unit tests for routing and the production download URL builder.
Download routing after this change:
files.get?alt=media&acknowledgeAbuse=true&supportsAllDrives=truefiles.export→ DOCXfiles.export→ XLSXfiles.export→ PPTXfiles.export→ PDFfiles.export→ JSONGoogle Drive limits
files.exportresponses to 10 MB. Larger Workspace exports and some Workspace file types require thefiles.downloadlong-running-operation flow, which is intentionally outside the scope of this PR.Exported-file filename/content-disposition rewriting is also outside this PR because the current
model.Linkabstraction does not provide a clean driver-local mechanism for overriding the resulting filename./ 此 PR 包含破坏性变更。
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
/ 此 PR 需要关联仓库同步修改。
Related repository PRs / 关联仓库 PR:
Testing / 测试
Verified with:
go build ./drivers/google_drive/... go test -vet=off ./drivers/google_drive/... -v gofmt -l drivers/google_drive/Results:
go build ./drivers/google_drive/...— passgo test -vet=off ./drivers/google_drive/... -v— 28 subcases passgofmt -l drivers/google_drive/— cleanThe tests cover:
application/vnd.google-apps.*MIME typesA normal:
go test ./drivers/google_drive/...currently fails during
go vetbecause of two pre-existingfmt.Errorf(e.Error)calls inrefreshToken(). Those lines are unchanged by this PR and were intentionally left outside the scope of this fix.go test ./...Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 我已按适用情况使用
gofmt、go fmt或prettier格式化变更代码。/ 我已在适用情况下请求相关维护者或代码所有者审查。
AI Disclosure / AI 使用声明
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
Usage scope / 使用范围:
Code generation / 代码生成
Refactoring / 重构
Documentation / 文档
Tests / 测试
Translation / 翻译
Review assistance / 审查辅助
I have reviewed and validated all AI-assisted content included in this PR.
/ 我已审核并验证此 PR 中的所有 AI 辅助内容。
I have ensured that all AI-assisted commits include
Co-Authored-Byattribution./ 我已确保所有 AI 辅助提交都包含
Co-Authored-By归属信息。I can reproduce all AI-assisted content included in this PR without any AI tools.
/ 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。