feat: populate muxvideo name uploadUrl and uploadId from r2#9067
feat: populate muxvideo name uploadUrl and uploadId from r2#9067
Conversation
…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>
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
View your CI Pipeline Execution ↗ for commit d9de7da
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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 | 🟠 MajorResolve the R2 row before importing into Mux.
createVideoFromUrlis a non-idempotent external write. The new DB lookup happens afterward, andr2Asset?.idsilently stores nouploadIdwhen the R2 row is missing. Lookup and validate first, then user2Asset.id.libs/prisma/media/db/schema.prisma:87-107showsCloudflareR2.publicUrlis 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
📒 Files selected for processing (1)
apis/api-media/src/schema/mux/video/video.ts
Summary by CodeRabbit