Skip to content

feat(download): support user-token downloads with Range fallback#155

Open
binee3162 wants to merge 2 commits into
riba2534:mainfrom
binee3162:feat/user_token_downloads
Open

feat(download): support user-token downloads with Range fallback#155
binee3162 wants to merge 2 commits into
riba2534:mainfrom
binee3162:feat/user_token_downloads

Conversation

@binee3162
Copy link
Copy Markdown

Title

fix(download): support user-token downloads with Range fallback

Summary

Fix msg resource-download when --user-access-token is provided, and add large-file Range fallback for both message resources and Drive file downloads.

The generated Lark Go SDK currently marks MessageResource.Get as tenant-token only, so passing WithUserAccessToken(...) fails with:

tenant token type not match user access token

However, the raw OpenAPI endpoint:

GET /open-apis/im/v1/messages/:message_id/resources/:file_key

can download resources with a user access token when the resource is visible to that user.

This PR preserves the existing SDK-based tenant/app-token path by default, and uses raw HTTP only when --user-access-token is explicitly provided. It also adds HTTP Range fallback for large downloads when Feishu returns file-size-limit errors.

Changes

  • Use raw HTTP for message resource downloads when a User Token is provided.
  • Preserve existing SDK-based tenant/app-token behavior when no User Token is provided.
  • Add shared HTTP Range download helper:
    • sends Range: bytes=start-end
    • validates Content-Range
    • writes chunks sequentially
    • removes partial output on failure
  • Apply Range fallback to:
    • msg resource-download
    • file download
    • drive download
    • callers using DownloadFileWithToken
  • Stream successful raw downloads directly to disk instead of loading the full file into memory.
  • Update command help, README, and skill docs with User Token and large-file examples.

Tests

Added tests for:

  • successful User Token message resource download
  • API error propagation
  • no tenant token request when User Token is explicit
  • message resource Range fallback
  • Drive file Range fallback

Verification

  • go test ./internal/client
  • go test ./cmd
  • git diff --check

Manual verification from the User Token resource path:

  • Downloaded a real message video resource with --user-access-token
  • Output content type: video/quicktime
  • Output size: 3,803,728 bytes

@binee3162
Copy link
Copy Markdown
Author

@riba2534 瞅瞅

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