-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Move video to folder #1131
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
Closed
+1,054
−329
Closed
Move video to folder #1131
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
568e885
implement video folder movement functionality
Enejivk 91415b3
fix: resolve server action build errors and add space video support
Enejivk a15335a
fix: guard against partial space updates in moveVideosToFolder
Enejivk 5d8d23c
fix: add space permission checks to moveVideosToFolder action
Enejivk ea8994c
fix: implement folder scope isolation and EffectRuntime migration
Enejivk c2d5606
refactor: improve folder security and cache management
Enejivk 0ab0856
refactor: rename FolderSelectionDialog to follow kebab-case convention
Enejivk b84ad4b
fix: implement accurate per-folder cache deltas and recursive updates
Enejivk e360651
renaming moveVideosToFolder to move-videos-to-folder
Enejivk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| "use server"; | ||
|
|
||
| import { getCurrentUser } from "@cap/database/auth/session"; | ||
| import { CurrentUser } from "@cap/web-domain"; | ||
| import { Effect } from "effect"; | ||
| import { getAllFolders } from "../../lib/folder"; | ||
| import { runPromise } from "../../lib/server"; | ||
|
|
||
| export async function getAllFoldersAction( | ||
| root: | ||
| | { variant: "user" } | ||
| | { variant: "space"; spaceId: string } | ||
| | { variant: "org"; organizationId: string } | ||
| ) { | ||
| try { | ||
| const user = await getCurrentUser(); | ||
| if (!user || !user.activeOrganizationId) { | ||
| return { | ||
| success: false as const, | ||
| error: "Unauthorized or no active organization", | ||
| }; | ||
| } | ||
|
|
||
| const folders = await runPromise( | ||
| getAllFolders(root).pipe(Effect.provideService(CurrentUser, user)) | ||
| ); | ||
| return { success: true as const, folders }; | ||
| } catch (error) { | ||
| console.error("Error fetching folders:", error); | ||
| return { | ||
| success: false as const, | ||
| error: "Failed to fetch folders", | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| "use server"; | ||
|
|
||
| import { getCurrentUser } from "@cap/database/auth/session"; | ||
| import { CurrentUser, Video, Folder, Policy } from "@cap/web-domain"; | ||
| import { SpacesPolicy } from "@cap/web-backend"; | ||
| import { Effect } from "effect"; | ||
| import { moveVideosToFolder } from "../../lib/folder"; | ||
| import { runPromise } from "../../lib/server"; | ||
| import { revalidatePath } from "next/cache"; | ||
|
|
||
| interface MoveVideosToFolderParams { | ||
| videoIds: string[]; | ||
| targetFolderId: string | null; | ||
| spaceId?: string | null; | ||
| } | ||
|
|
||
| export async function moveVideosToFolderAction({ | ||
| videoIds, | ||
| targetFolderId, | ||
| spaceId, | ||
| }: MoveVideosToFolderParams) { | ||
| try { | ||
| const user = await getCurrentUser(); | ||
| if (!user || !user.activeOrganizationId) { | ||
| return { | ||
| success: false as const, | ||
| error: "Unauthorized or no active organization", | ||
| }; | ||
| } | ||
|
|
||
| const typedVideoIds = videoIds.map((id) => Video.VideoId.make(id)); | ||
| const typedTargetFolderId = targetFolderId | ||
| ? Folder.FolderId.make(targetFolderId) | ||
| : null; | ||
|
|
||
| const root = spaceId | ||
| ? { variant: "space" as const, spaceId } | ||
| : { variant: "org" as const, organizationId: user.activeOrganizationId }; | ||
|
|
||
| const moveVideosEffect = spaceId | ||
| ? Effect.gen(function* () { | ||
| const spacesPolicy = yield* SpacesPolicy; | ||
|
|
||
| return yield* moveVideosToFolder( | ||
| typedVideoIds, | ||
| typedTargetFolderId, | ||
| root | ||
| ).pipe(Policy.withPolicy(spacesPolicy.isMember(spaceId))); | ||
| }).pipe(Effect.provideService(CurrentUser, user)) | ||
| : moveVideosToFolder(typedVideoIds, typedTargetFolderId, root).pipe( | ||
| Effect.provideService(CurrentUser, user) | ||
| ); | ||
|
|
||
| const result = await runPromise(moveVideosEffect); | ||
|
|
||
| revalidatePath("/dashboard/caps"); | ||
|
|
||
| if (spaceId) { | ||
| revalidatePath(`/dashboard/spaces/${spaceId}`); | ||
| result.originalFolderIds.forEach((folderId) => { | ||
| if (folderId) { | ||
| revalidatePath(`/dashboard/spaces/${spaceId}/folder/${folderId}`); | ||
| } | ||
| }); | ||
| if (result.targetFolderId) { | ||
| revalidatePath( | ||
| `/dashboard/spaces/${spaceId}/folder/${result.targetFolderId}` | ||
| ); | ||
| } | ||
| } else { | ||
| result.originalFolderIds.forEach((folderId) => { | ||
| if (folderId) { | ||
| revalidatePath(`/dashboard/folder/${folderId}`); | ||
| } | ||
| }); | ||
| if (result.targetFolderId) { | ||
| revalidatePath(`/dashboard/folder/${result.targetFolderId}`); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true as const, | ||
| message: `Successfully moved ${result.movedCount} video${ | ||
| result.movedCount !== 1 ? "s" : "" | ||
| } to ${result.targetFolderId ? "folder" : "root"}`, | ||
| movedCount: result.movedCount, | ||
| originalFolderIds: result.originalFolderIds, | ||
| targetFolderId: result.targetFolderId, | ||
| videoCountDeltas: result.videoCountDeltas, | ||
| }; | ||
| } catch (error) { | ||
| console.error("Error moving videos to folder:", error); | ||
| return { | ||
| success: false as const, | ||
| error: error instanceof Error ? error.message : "Failed to move videos", | ||
| }; | ||
| } | ||
| } | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rename file to follow kebab-case convention.
The filename
moveVideosToFolder.tsviolates the repository's kebab-case convention for TypeScript modules. As per coding guidelinesRename the file:
Update the import in any files that reference this action:
🤖 Prompt for AI Agents