Skip to content

fix(google_drive): support Google Workspace native file exports - #3137

Draft
mythic3011 wants to merge 6 commits into
OpenListTeam:mainfrom
mythic3011:fix/google-drive-workspace-export
Draft

mythic3011 wants to merge 6 commits into
OpenListTeam:mainfrom
mythic3011:fix/google-drive-workspace-export

Conversation

@mythic3011

@mythic3011 mythic3011 commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary / 摘要

Fix Google Drive downloads for Google Workspace-native files.

Previously, the Google Drive driver used files.get?alt=media for all files. Google Drive only supports that download path for blob/binary files. Google Workspace-native files such as Docs, Sheets, and Slides must use files.export.

This caused Workspace-native files to fail with:

Only files with binary content can be downloaded. Use Export with Docs Editors files.

This PR:

  • Fetches mimeType and capabilities.canDownload in Link() 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:

    • Google Docs → DOCX
    • Google Sheets → XLSX
    • Google Slides → PPTX
    • Google Drawings → PDF
    • Apps Script → JSON
  • 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:

Source type Download path
Blob/binary files files.get?alt=media&acknowledgeAbuse=true&supportsAllDrives=true
Google Docs files.export → DOCX
Google Sheets files.export → XLSX
Google Slides files.export → PPTX
Google Drawings files.export → PDF
Apps Script files.export → JSON
Known unsupported native types Explicit driver error
Other/unrecognized Drive MIME types Existing media-download fallback

Google Drive limits files.export responses to 10 MB. Larger Workspace exports and some Workspace file types require the files.download long-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.Link abstraction does not provide a clean driver-local mechanism for overriding the resulting filename.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend: N/A
  • OpenList-Docs: N/A

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/... — pass
  • go test -vet=off ./drivers/google_drive/... -v — 28 subcases pass
  • gofmt -l drivers/google_drive/ — clean

The tests cover:

  • binary/media routing
  • Docs/Sheets/Slides/Drawing/Script export routing
  • known unsupported Workspace-native types
  • compatibility fallback for unrecognized application/vnd.google-apps.* MIME types
  • media URL construction and query parameters
  • export URL construction and query parameters

A normal:

go test ./drivers/google_drive/...

currently fails during go vet because of two pre-existing fmt.Errorf(e.Error) calls in refreshToken(). Those lines are unchanged by this PR and were intentionally left outside the scope of this fix.

  • go test ./...
  • Manual test / 手动测试: Not yet performed against a live Google Drive file after the patch.

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmt、go fmt 或 prettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明):

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-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

- 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
mythic3011 force-pushed the fix/google-drive-workspace-export branch from 4852081 to d96708e Compare September 24, 2026 19:40
Replace googleWorkspaceUnsupported messages with consistent wording for
LRO-only types, drive-sdk shortcuts, and My Maps.
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.

1 participant