-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: add videos from caps #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import { db } from "@cap/database"; | ||
| import { getCurrentUser } from "@cap/database/auth/session"; | ||
| import { nanoId } from "@cap/database/helpers"; | ||
| import { | ||
| folders, | ||
| sharedVideos, | ||
|
|
@@ -50,7 +51,39 @@ export async function addVideosToFolder( | |
|
|
||
| const isAllSpacesEntry = spaceId === user.activeOrganizationId; | ||
|
|
||
| //if video already exists in the space, then move it | ||
| //if we're adding videos to a folder from Caps page, then insert the videos into the folder | ||
| if (isAllSpacesEntry && folder.spaceId) { | ||
| await db() | ||
| .insert(sharedVideos) | ||
| .values( | ||
| validVideoIds.map((videoId) => { | ||
| const id = nanoId(); | ||
| return { | ||
| id, | ||
| videoId, | ||
| folderId, | ||
| organizationId: user.activeOrganizationId, | ||
| sharedByUserId: user.id, | ||
| }; | ||
| }), | ||
| ); | ||
| } else { | ||
| await db() | ||
| .insert(spaceVideos) | ||
| .values( | ||
| validVideoIds.map((videoId) => { | ||
| const id = nanoId(); | ||
| return { | ||
| id, | ||
| videoId, | ||
| folderId, | ||
| spaceId, | ||
| addedById: user.id, | ||
| }; | ||
| }), | ||
| ); | ||
| } | ||
|
Comment on lines
+54
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainDuplicate records: Insert followed by update on same videos. The new insertion logic creates records for
Neither Run this script to check for unique constraints and potential duplicate risks: 🏁 Script executed: #!/bin/bash
# Verify schema constraints and search for existing duplicate-prevention logic
# Check schema definitions for unique constraints
rg -nP -A5 'export const (sharedVideos|spaceVideos) = mysqlTable' packages/database/schema.ts
# Search for upsert or duplicate-handling patterns in similar code
rg -nP --type=ts -C3 '\.(insert|upsert)\((sharedVideos|spaceVideos)\)' apps/web/actions/
# Look for existing duplicate checks
rg -nP --type=ts -C3 'onConflict|onDuplicate|IGNORE|REPLACE' apps/web/actions/Length of output: 3821 🏁 Script executed: #!/bin/bash
# Show validVideoIds usage
rg -n -C5 'validVideoIds' apps/web/actions/folders/add-videos.ts
# Show any update queries
rg -n -C5 '\.update' apps/web/actions/folders/add-videos.tsLength of output: 2416 Prevent duplicate folder associations in folders/add-videos.ts |
||
|
|
||
| if (isAllSpacesEntry) { | ||
| await db() | ||
| .update(sharedVideos) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition mismatch between insert and update blocks.
The insert block (line 55) uses
isAllSpacesEntry && folder.spaceId, while the update block (line 87) only checksisAllSpacesEntry. This creates inconsistent routing:isAllSpacesEntry = true,folder.spaceId = nullspaceVideos(else branch)sharedVideosEnsure both blocks use the same condition to maintain consistency. If
folder.spaceIdis required forsharedVideos, include it in the update condition as well.Apply this diff to align the conditions:
Also applies to: 87-87
🤖 Prompt for AI Agents