Skip to content

feat: add new source.uploadMedia API - #645

Merged
tripodsan merged 6 commits into
mainfrom
media-upload
Aug 7, 2026
Merged

feat: add new source.uploadMedia API#645
tripodsan merged 6 commits into
mainfrom
media-upload

Conversation

@tripodsan

Copy link
Copy Markdown
Contributor

Summary

  • Adds test coverage for the new source.uploadMedia({ org, site, path, body }) API in nx2/utils/api.js: legacy delegation to _saveDA as FormData (including the stage content.da.livestage-content.da.live contentUrl rewrite), hlx6 POSTs to the AEM media route with the correct content-type header, contentUrl prefix-normalization against the site's aem.page origin, non-ok passthrough for both branches, and the /org/site/path string call form.
  • While writing the tests, found and fixed two bugs in the (previously uncommitted) uploadMedia implementation:
    1. The non-hlx6 branch fell through to also POST to the hlx6-only media endpoint whenever DA_ADMIN wasn't exactly 'https://stage-admin.da.live' — i.e. for ordinary non-hlx6 sites in most environments, uploadMedia made an unintended second request after _saveDA had already completed. Fixed by returning unconditionally after the _saveDA call.
    2. In this repo's dev/test env DA_ADMIN is 'https://stage-admin.da.live', so the stage-content rewrite branch always runs for non-hlx6 uploads. When the returned contentUrl's host wasn't content.da.live (no rewrite needed), the code had already consumed the response body via resp.json() and then returned that same drained Response — any caller calling resp.json() again would hit a "body stream already read" error. Fixed by always returning adaptJsonResponse(resp, json) in that branch.

Test plan

  • npm run test:file -- ./test/nx2/utils/api.test.js — 120/120 passing (11 new tests for uploadMedia)
  • npm test (full suite) — all tests pass in isolation; the shared full-suite run is intermittently flaky under --concurrent-browsers 4 on unrelated test files (pre-existing, not touched by this change)
  • npx eslint nx2/utils/api.js test/nx2/utils/api.test.js — clean

🤖 Generated with Claude Code

tripodsan and others added 3 commits August 6, 2026 13:45
…bugs

Adds tests for the new source.uploadMedia API (legacy FormData delegation
with the stage content.da.live -> stage-content.da.live rewrite, hlx6 media
POST with content-type + contentUrl normalization, non-ok passthrough, and
the path-string call form). Writing the tests surfaced two bugs in the
uncommitted uploadMedia implementation, both fixed here: a fallthrough that
made non-hlx6 uploads also hit the hlx6-only media endpoint, and a
body-stream-already-read bug where a successful non-hlx6 response without a
content.da.live host was returned after its body had already been consumed.
@aem-code-sync

aem-code-sync Bot commented Aug 6, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@tripodsan tripodsan changed the title test: add coverage for source.uploadMedia feat: add new source.uploadMedia API Aug 6, 2026
Comment thread nx2/utils/api.js Outdated
@tripodsan
tripodsan requested a review from kptdobe August 6, 2026 20:30
Comment thread nx2/utils/api.js
Comment on lines +782 to 784
function adaptJsonResponse(resp, obj) {
return new Response(JSON.stringify(obj), resp);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@anfibiacreativa better :-) ?

kptdobe
kptdobe previously approved these changes Aug 7, 2026
@tripodsan
tripodsan requested a review from kptdobe August 7, 2026 08:56
@tripodsan
tripodsan merged commit 2db3d54 into main Aug 7, 2026
3 checks passed
@tripodsan
tripodsan deleted the media-upload branch August 7, 2026 09:01
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.

3 participants