feat(im): complete audio/post rendering and add opt-in --download-resources#1245
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds opt-in IM message resource extraction and bounded-concurrency downloads, threads resource refs through formatting and thread expansion, wires a --download-resources CLI flag into three shortcuts with safe local paths, and includes tests and docs; also updates post styling and audio rendering tests. ChangesIM resource extraction and download flow
Message rendering updates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@shortcuts/im/convert_lib/resource_download.go`:
- Line 14: The inline comment containing "在地写盘" should be changed to English for
consistency—replace that phrase in the comment line "// the reactions
batch_query fan-out (4): each download is a GET +在地写盘, and" with a clear English
equivalent such as "write to local disk" (resulting comment: "// the reactions
batch_query fan-out (4): each download is a GET + write to local disk, and") so
the comment reads entirely in English.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3a188b41-3aa9-4b6d-a66c-86cf5ad396fd
📒 Files selected for processing (18)
.gitignoreshortcuts/im/convert_lib/content_convert.goshortcuts/im/convert_lib/content_media_misc_test.goshortcuts/im/convert_lib/media.goshortcuts/im/convert_lib/resource_download.goshortcuts/im/convert_lib/resource_download_test.goshortcuts/im/convert_lib/resource_extract.goshortcuts/im/convert_lib/resource_extract_test.goshortcuts/im/convert_lib/text.goshortcuts/im/convert_lib/text_test.goshortcuts/im/convert_lib/thread.goshortcuts/im/convert_lib/thread_test.goshortcuts/im/im_chat_messages_list.goshortcuts/im/im_download_resources.goshortcuts/im/im_messages_mget.goshortcuts/im/im_resource_download_test.goshortcuts/im/im_threads_messages_list.gotests/cli_e2e/im/im_download_resources_dryrun_test.go
d07320b to
9f67c35
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1245 +/- ##
==========================================
+ Coverage 69.19% 71.99% +2.80%
==========================================
Files 637 702 +65
Lines 59753 66502 +6749
==========================================
+ Hits 41345 47880 +6535
+ Misses 15067 14905 -162
- Partials 3341 3717 +376 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9d95d5d7e3dca1f8b35eb3f69329139ab57888e0🧩 Skill updatenpx skills add sammi-bytedance/larksuite-cli#feat/im-info-completion -y -g |
c2343da to
4d1f9f0
Compare
…ources Block 1 — field completion: audio renders <audio key="..." duration="Xs"/> (falls back to [Voice: Xs]/[Voice]); post renders emotion -> :emoji_type:, applies text.style (bold/italic/underline/lineThrough), passes through md; sticker unchanged. Block 2 — opt-in --download-resources (default off) on +chat-messages-list, +messages-mget, +threads-messages-list: extract downloadable resource refs during formatting (image/file/audio/video/media + post-embedded; sticker excluded; merge_forward sub-items carry the top-level container message_id, since the resources endpoint rejects sub-item ids with "234003 File not in msg" and can only fetch a forwarded resource through the container; thread replies get their own block), then download each distinct (message_id, file_key) once into ./lark-im-resources/ with bounded concurrency (3), filling back local_path/size_bytes; single-resource failures are isolated (error:true + stderr warning). Path safety reuses normalizeDownloadOutputPath + ResolveSavePath. Batch download keys each file on disk by its unique file_key basename and only appends an extension (from the Content-Disposition filename or MIME type) — it does NOT substitute the server's Content-Disposition filename. Otherwise two resources whose servers return the same filename (e.g. download.bin) would resolve to the same ./lark-im-resources/ path and clobber each other concurrently. The friendly "adopt the server filename" behavior is kept only for an explicit +messages-resources-download with no --output. Resource ref extraction guards against self-referential / cyclic merge_forward prefetch maps (a real API sub-item list can include the container's own id or a back-pointing merge_forward) via a visited set, so extraction terminates instead of overflowing the stack. The container message_id is threaded through nested merge_forwards as the download owner. Also: document the feature (including the im:message:readonly scope requirement) in skills/lark-im — SKILL.md is generated from skill-template/domains/im.md (edit the source), plus the hand-written message-enrichment + 3 command references. Change-Id: I3a71d7d1b193130f551aaa2ec180ac1500d59ac4 Meego: https://meego.larkoffice.com/5e96d7bff4e7c525510f9156/story/detail/7331555925
4d1f9f0 to
9d95d5d
Compare
Rebased onto main v1.0.54, which added IM content after this branch forked. Fold main's new facts into the slimmed/gotcha-only form and fix drift: - SKILL.md: compact the newly-merged chat.user_setting / chat.managers / chat.moderation API resources to the api_compact `action`(identity) form (consistent with the rest; regen-equivalent), and note the opt-in `--download-resources` flag on the three message-pulling shortcuts. - chat-search: fix stale `--sort-by` -> `--sort`, add `--chat-modes`, and fold the "`--sort` is always descending" caution (#1302/#1317). - chat-messages-list: note `--order` is the only sort axis (no field sort). - messages-send: split @mention by message type; interactive cards are not normalized and need card-native `<at>` syntax (#1419). - flag-cancel: document best-effort double-cancel (feed layer skipped with a stderr warning when chat type is undeterminable). - feed-group-list-item / query-item: p2p cards omit chat_name; resolve via chats/batch_query -> p2p_target_id -> contact lookup. - message-enrichment: add the `--download-resources` contract (merge_forward container-id 234003 trap, fail-silent isolation, no extra scope) (#1245). Docs only; no Go/--help/Desc changes.
Summary
Complete IM message rendering (audio
file_key+ postemotion/text.style/md) and add an opt-in--download-resourcesflag that auto-downloads message resources into./lark-im-resources/. Default behavior and request count are unchanged when the flag is off.Changes
audio→<audio key="..." duration="Xs"/>(falls back to[Voice: Xs]/[Voice]);postrendersemotion→:emoji_type:, appliestext.style(bold/italic/underline/lineThrough), passes throughmd;stickerunchanged.--download-resourcesflag on+chat-messages-list,+messages-mget,+threads-messages-list: extracts downloadable resource refs (image/file/audio/video/media + post-embedded; sticker excluded) during formatting, then a bounded-concurrency (=3) engine downloads each distinct(message_id, file_key)once into./lark-im-resources/, filling backlocal_path/size_bytes. Single-resource failures are isolated (error:true+ stderr warning).normalizeDownloadOutputPath+ResolveSavePath(rejects separators /../ absolute paths).shortcuts/im/convert_lib/resource_extract.go,resource_download.go,shortcuts/im/im_download_resources.go. Back-compat gated wrappers added incontent_convert.go/thread.go.skills/lark-im(SKILL.md, message-enrichment + 3 command references),CHANGELOG.md.Test Plan
go test ./shortcuts/im/convert_lib/ ./shortcuts/im/, incl.-raceon the download engine)lark-cli im +chat-messages-listdry-run flow works as expected (go test ./tests/cli_e2e/im/ -run TestIM_DownloadResourcesDryRun);golangci-lint v2.1.60 issues,gofmt/go vetcleanSummary by CodeRabbit
New Features
Documentation