Skip to content

Stream media downloads and add --url and --from-event - #10

Merged
purpshell merged 2 commits into
devfrom
codex/media-download
Sep 23, 2026
Merged

purpshell merged 2 commits into
devfrom
codex/media-download

Conversation

@purpshell

@purpshell purpshell commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

polymorfa media download streams attachments to disk and adds --url and --from-event.

  • media download <id> --output <path> retrieves metadata, then streams the response into a private temporary sibling file. The default 100 MiB limit applies to declared sizes and arriving bytes; --max-bytes changes it. An existing destination is preserved unless --force is supplied, and handled failures attempt to remove the temporary file.
  • Storage redirects are followed without the Polymorfa API key.
  • --url prints the short-lived signed storage link and warns on stderr. If the API streams the file instead, the command exits 2 and directs the user to --output.
  • --from-event <file> reads a stored message webhook or its payload, downloads from the WhatsApp CDN, and verifies and decrypts the attachment without a Polymorfa credential. --timeout aborts the actual fetch. Invalid or missing event files and integrity failures exit 2; errors do not print the media descriptor.

The SDK dependency is the published npm version @polymorfa/sdk@0.1.0-dev.20260922102711, pinned in both package.json and package-lock.json. The CLI uses the installed MessagingClient.media.downloadStream, downloadUrl, and @polymorfa/sdk/node helpers. The previous unmerged SDK Git pin is no longer the dependency.

Six-part assessment

Part Status Evidence or remaining work
API Unaffected Uses the existing Messaging media download and metadata routes. The CLI rejects client tokens for API-backed media access; storage redirects receive no API credential. No server route, scope, response shape, or enrollment policy changes here.
SDKs Unaffected implementation; dependency verified The rebased CLI already pins npm 0.1.0-dev.20260922102711; the installed artifact supplies all three download helpers and propagates the abort signal to the CDN fetch. This PR does not change the dependency manifest or require another SDK change.
CLI Updated Download modes, bounded file streaming, validation, timeout handling, and command help are covered by focused command tests.
Docs Updated locally; publication blocked on CLI release README.md documents the modes. The existing dependency guide records the npm pin. Prepared internal launch copy adds all download modes and restrictions to monorepo docs/guides/communicate/api/download-linked-media.mdx. Publish that copy alongside the CLI release; add a changelog entry only for confirmed customer availability.
Feature releases Unaffected controls; release acceptance pending The CLI remains unpublished. No feature flag, entitlement, or enrollment change. Installing the dependency and passing tests do not establish CLI publication or live API/CDN acceptance.
Admin controls Unaffected Adds local download/output behavior, with no new server state, grant, staff action, or operational control. Existing media ownership checks remain authoritative.

Verification

Verified CLI head: d836d96cad97a766b1352ce4690884b9faf61845.

  • Exact-head CI completed successfully. The checked-in workflow runs npm ci and npm run verify on Node 22; verify includes formatting, lint, typecheck, tests, build, package dry-run, and production dependency audit.

  • Independent exact-head archive: offline dependency installation, build, and all 18 tests in test/commands/media.test.ts passed on Node 24.15.0. Coverage includes size limits, redirected requests without credentials, signed URLs, overwrite protection, integrity failure cleanup, missing-file exit 2, and a fetch that only rejects when its timeout signal aborts.

  • The installed npm SDK's download path was traced through the Node file helper to its actual fetch signal.

  • Prepared media documentation examples match the compiled command help at this head.

Not exercised: a live API storage redirect, a real WhatsApp CDN object, or an installed released CLI. Publishing the prepared customer documentation alongside the CLI release and completing live release acceptance remain outstanding.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 75 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 5cee978e-a6bf-48a1-8533-19f7b7ec2f66

📥 Commits

Reviewing files that changed from the base of the PR and between 0895876 and d836d96.

📒 Files selected for processing (5)
  • README.md
  • src/commands/media/download.ts
  • src/errors/present.ts
  • src/services/media.ts
  • test/commands/media.test.ts

Comment @coderabbitai help to get the list of available commands.

@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T11:47:29.664913Z d836d96 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed284f632e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/media/download.ts Resolved
Comment thread src/services/media.ts Resolved
- media download streams through a temp file (SDK downloadStream/writeStreamToFile),
  follows storage redirects without the API key, enforces --max-bytes while streaming
- --url prints the short-lived signed link with a stderr warning
- --from-event decrypts WhatsApp CDN media from a stored webhook (no credential)
- map PolymorfaMediaIntegrityError to a non-retryable validation error
- pin @polymorfa/sdk to polymorfa/sdks@5a7245d (unmerged codex/media-download)
@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d836d96cad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@purpshell
purpshell marked this pull request as ready for review September 23, 2026 09:27
@purpshell
purpshell merged commit 2540576 into dev Sep 23, 2026
3 checks passed
@purpshell
purpshell deleted the codex/media-download branch October 26, 2026 15:52
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