Skip to content

feat: populate muxvideo name uploadUrl and uploadId from r2#9067

Open
tanflem wants to merge 1 commit intomainfrom
tannerfleming/vmt-235-populate-muxvideo-name-uploadurl-and-uploadid-from-r2-asset
Open

feat: populate muxvideo name uploadUrl and uploadId from r2#9067
tanflem wants to merge 1 commit intomainfrom
tannerfleming/vmt-235-populate-muxvideo-name-uploadurl-and-uploadid-from-r2-asset

Conversation

@tanflem
Copy link
Copy Markdown
Contributor

@tanflem tanflem commented Apr 23, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved video creation by ensuring proper retrieval and assignment of upload metadata, enhancing data consistency.

…asset

Previously createMuxVideoAndQueueUpload left these three MuxVideo columns
null. Use originalFilename as the human-readable name, r2PublicUrl as
uploadUrl, and look up the source CloudflareR2 row by publicUrl to set
uploadId — giving every MuxVideo traceability back to its R2 source.

Refs VMT-235

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tanflem tanflem requested a review from Kneesal April 23, 2026 16:15
@tanflem tanflem self-assigned this Apr 23, 2026
@linear
Copy link
Copy Markdown

linear Bot commented Apr 23, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Walkthrough

The createMuxVideoAndQueueUpload mutation was enhanced to look up the Cloudflare R2 asset by its public URL and populate new MuxVideo properties during creation, including name, uploadUrl, and uploadId.

Changes

Cohort / File(s) Summary
MuxVideo Creation Enhancement
apis/api-media/src/schema/mux/video/video.ts
Added R2 asset lookup by r2PublicUrl to enrich MuxVideo creation with asset metadata: sets name from originalFilename, stores r2PublicUrl as uploadUrl, and assigns uploadId from R2 asset (nullable).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: populating MuxVideo properties (name, uploadUrl, uploadId) from R2 asset data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tannerfleming/vmt-235-populate-muxvideo-name-uploadurl-and-uploadid-from-r2-asset

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.

❤️ Share

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 23, 2026

View your CI Pipeline Execution ↗ for commit d9de7da

Command Status Duration Result
nx affected --target=subgraph-check --base=4cc3... ✅ Succeeded 2s View ↗
nx affected --target=extract-translations --bas... ✅ Succeeded <1s View ↗
nx affected --target=lint --base=4cc30b3f1b459a... ✅ Succeeded 28s View ↗
nx affected --target=type-check --base=4cc30b3f... ✅ Succeeded 23s View ↗
nx run-many --target=codegen --all --parallel=3 ✅ Succeeded 2s View ↗
nx run-many --target=prisma-generate --all --pa... ✅ Succeeded 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-23 18:06:43 UTC

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apis/api-media/src/schema/mux/video/video.ts (1)

269-288: ⚠️ Potential issue | 🟠 Major

Resolve the R2 row before importing into Mux.

createVideoFromUrl is a non-idempotent external write. The new DB lookup happens afterward, and r2Asset?.id silently stores no uploadId when the R2 row is missing. Lookup and validate first, then use r2Asset.id. libs/prisma/media/db/schema.prisma:87-107 shows CloudflareR2.publicUrl is nullable, so this miss is possible.

Proposed fix
-      const muxAsset = await createVideoFromUrl(
-        r2PublicUrl,
-        false,
-        '2160p',
-        downloadable ?? true
-      )
-
       const r2Asset = await prisma.cloudflareR2.findFirst({
         where: { publicUrl: r2PublicUrl },
         select: { id: true }
       })
 
+      if (r2Asset == null) {
+        throw new GraphQLError('R2 asset not found', {
+          extensions: { code: 'NOT_FOUND' }
+        })
+      }
+
+      const muxAsset = await createVideoFromUrl(
+        r2PublicUrl,
+        false,
+        '2160p',
+        downloadable ?? true
+      )
+
       const muxVideo = await prisma.muxVideo.create({
         ...query,
         data: {
           assetId: muxAsset.id,
           userId: user.id,
           name: originalFilename,
           uploadUrl: r2PublicUrl,
-          uploadId: r2Asset?.id,
+          uploadId: r2Asset.id,
           downloadable: downloadable ?? true
         }
       })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apis/api-media/src/schema/mux/video/video.ts` around lines 269 - 288, The
code calls createVideoFromUrl before ensuring the CloudflareR2 DB row exists,
causing a non-idempotent external write and possibly storing null uploadId;
change the flow to first run the prisma.cloudflareR2.findFirst (validate that
r2Asset exists and has an id), throw or return an error if missing, then call
createVideoFromUrl and finally create the prisma.muxVideo record using the
confirmed r2Asset.id (replace r2Asset?.id with the validated id); reference
createVideoFromUrl, prisma.cloudflareR2.findFirst, and prisma.muxVideo.create
when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apis/api-media/src/schema/mux/video/video.ts`:
- Around line 269-288: The code calls createVideoFromUrl before ensuring the
CloudflareR2 DB row exists, causing a non-idempotent external write and possibly
storing null uploadId; change the flow to first run the
prisma.cloudflareR2.findFirst (validate that r2Asset exists and has an id),
throw or return an error if missing, then call createVideoFromUrl and finally
create the prisma.muxVideo record using the confirmed r2Asset.id (replace
r2Asset?.id with the validated id); reference createVideoFromUrl,
prisma.cloudflareR2.findFirst, and prisma.muxVideo.create when making the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a5febff0-8473-40c3-aa48-3cca810fc02f

📥 Commits

Reviewing files that changed from the base of the PR and between 4cc30b3 and d9de7da.

📒 Files selected for processing (1)
  • apis/api-media/src/schema/mux/video/video.ts

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