From cc6429a7d1153277e52aa0c6ad09bd6a0876d7b0 Mon Sep 17 00:00:00 2001 From: mogita Date: Sun, 3 Aug 2025 16:47:00 +0800 Subject: [PATCH 01/13] feat: set video private by default --- packages/database/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/database/schema.ts b/packages/database/schema.ts index 2db1a7fef85..4022edba5dc 100644 --- a/packages/database/schema.ts +++ b/packages/database/schema.ts @@ -228,7 +228,7 @@ export const videos = mysqlTable( awsBucket: varchar("awsBucket", { length: 255 }), bucket: nanoIdNullable("bucket"), metadata: json("metadata").$type(), - public: boolean("public").notNull().default(true), + public: boolean("public").notNull().default(false), password: encryptedTextNullable("password"), videoStartTime: varchar("videoStartTime", { length: 255 }), audioStartTime: varchar("audioStartTime", { length: 255 }), From 93dfc9f16961159ce423e96b5e0a47b00e8177c6 Mon Sep 17 00:00:00 2001 From: mogita Date: Sun, 3 Aug 2025 18:14:50 +0800 Subject: [PATCH 02/13] feat: use dynamic public web url in embed code --- .../web/app/(org)/dashboard/caps/components/SharingDialog.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx index 665c5548774..1a6adc45133 100644 --- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx +++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx @@ -139,7 +139,7 @@ export const SharingDialog: React.FC = ({ const handleCopyEmbedCode = async () => { const embedCode = `
`; @@ -246,7 +246,7 @@ export const SharingDialog: React.FC = ({
{`
`}
From 37cfbb2ac1ce85d6348346ee12ed8495b24580c9 Mon Sep 17 00:00:00 2001 From: mogita Date: Sun, 3 Aug 2025 18:15:40 +0800 Subject: [PATCH 03/13] feat: toggle video sharing via the public column --- apps/web/actions/caps/share.ts | 12 +++- .../caps/components/SharingDialog.tsx | 59 ++++++++++++++----- .../s/[videoId]/_components/ShareHeader.tsx | 1 + 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/apps/web/actions/caps/share.ts b/apps/web/actions/caps/share.ts index 86853cb5582..3564775b193 100644 --- a/apps/web/actions/caps/share.ts +++ b/apps/web/actions/caps/share.ts @@ -10,9 +10,10 @@ import { nanoId } from "@cap/database/helpers" interface ShareCapParams { capId: string spaceIds: string[] + public?: boolean } -export async function shareCap({ capId, spaceIds }: ShareCapParams) { +export async function shareCap({ capId, spaceIds, public: isPublic }: ShareCapParams) { try { const user = await getCurrentUser() @@ -122,6 +123,15 @@ export async function shareCap({ capId, spaceIds }: ShareCapParams) { }) } } + + // Update public status if provided + if (typeof isPublic === 'boolean') { + await db() + .update(videos) + .set({ public: isPublic }) + .where(eq(videos.id, capId)) + } + revalidatePath('/dashboard/caps') revalidatePath(`/dashboard/caps/${capId}`) return { success: true } diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx index 1a6adc45133..47553bc646b 100644 --- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx +++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx @@ -8,12 +8,13 @@ import { DialogTitle, Input, Avatar, + Switch, } from "@cap/ui"; import { faShareNodes, faCopy } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import clsx from "clsx"; import { motion } from "framer-motion"; -import { Check, Search } from "lucide-react"; +import { Check, Search, Globe2 } from "lucide-react"; import Image from "next/image"; import { useCallback, useEffect, useState } from "react"; import { toast } from "sonner"; @@ -32,6 +33,7 @@ interface SharingDialogProps { organizationId: string; }[]; onSharingUpdated: (updatedSharedSpaces: string[]) => void; + isPublic?: boolean; } export const SharingDialog: React.FC = ({ @@ -41,6 +43,7 @@ export const SharingDialog: React.FC = ({ capName, sharedSpaces, onSharingUpdated, + isPublic = false, }) => { const { spacesData } = useDashboardContext(); const [selectedSpaces, setSelectedSpaces] = useState>(new Set()); @@ -49,9 +52,11 @@ export const SharingDialog: React.FC = ({ Set >(new Set()); const [loading, setLoading] = useState(false); - const tabs = ["Share to space", "Embed"] as const; + const [publicToggle, setPublicToggle] = useState(isPublic); + const [initialPublicState, setInitialPublicState] = useState(isPublic); + const tabs = ["Share", "Embed"] as const; const [activeTab, setActiveTab] = - useState<(typeof tabs)[number]>("Share to space"); + useState<(typeof tabs)[number]>("Share"); const sharedSpaceIds = new Set(sharedSpaces?.map((space) => space.id) || []); @@ -60,10 +65,12 @@ export const SharingDialog: React.FC = ({ const spaceIds = new Set(sharedSpaces.map((space) => space.id)); setSelectedSpaces(spaceIds); setInitialSelectedSpaces(spaceIds); + setPublicToggle(isPublic); + setInitialPublicState(isPublic); setSearchTerm(""); setActiveTab(tabs[0]); } - }, [isOpen, sharedSpaces]); + }, [isOpen, sharedSpaces, isPublic]); const isSpaceSharedViaOrganization = useCallback( (spaceId: string) => { @@ -92,6 +99,7 @@ export const SharingDialog: React.FC = ({ const result = await shareCap({ capId, spaceIds: Array.from(selectedSpaces), + public: publicToggle, }); if (!result.success) { @@ -108,22 +116,26 @@ export const SharingDialog: React.FC = ({ (id) => !newSelectedSpaces.includes(id) ); + const publicChanged = publicToggle !== initialPublicState; + const getSpaceName = (id: string) => { const space = spacesData?.find((space) => space.id === id); return space?.name || `Space ${id}`; }; - if (addedSpaceIds.length === 1 && removedSpaceIds.length === 0) { + if (publicChanged && addedSpaceIds.length === 0 && removedSpaceIds.length === 0) { + toast.success(publicToggle ? "Video is now public" : "Video is now private"); + } else if (addedSpaceIds.length === 1 && removedSpaceIds.length === 0 && !publicChanged) { toast.success(`Shared to ${getSpaceName(addedSpaceIds[0] as string)}`); - } else if (removedSpaceIds.length === 1 && addedSpaceIds.length === 0) { + } else if (removedSpaceIds.length === 1 && addedSpaceIds.length === 0 && !publicChanged) { toast.success( `Unshared from ${getSpaceName(removedSpaceIds[0] as string)}` ); - } else if (addedSpaceIds.length > 0 && removedSpaceIds.length === 0) { + } else if (addedSpaceIds.length > 0 && removedSpaceIds.length === 0 && !publicChanged) { toast.success(`Shared to ${addedSpaceIds.length} spaces`); - } else if (removedSpaceIds.length > 0 && addedSpaceIds.length === 0) { + } else if (removedSpaceIds.length > 0 && addedSpaceIds.length === 0 && !publicChanged) { toast.success(`Unshared from ${removedSpaceIds.length} spaces`); - } else if (addedSpaceIds.length > 0 && removedSpaceIds.length > 0) { + } else if (addedSpaceIds.length > 0 || removedSpaceIds.length > 0 || publicChanged) { toast.success(`Sharing settings updated`); } else { toast.info("No changes to sharing settings"); @@ -163,13 +175,13 @@ export const SharingDialog: React.FC = ({ } description={ - activeTab === "Share to space" - ? "Select the spaces you would like to share with" + activeTab === "Share" + ? "Select how you would like to share the cap" : "Copy the embed code to share your cap" } > - {activeTab === "Share to space" + {activeTab === "Share" ? `Share ${capName}` : `Embed ${capName}`} @@ -202,12 +214,29 @@ export const SharingDialog: React.FC = ({
- {activeTab === "Share to space" ? ( + {activeTab === "Share" ? ( <> + {/* Public sharing toggle */} +
+
+
+ +
+
+

Anyone with the link

+

Anyone with this link can view the video

+
+
+ +
+
setSearchTerm(e.target.value)} @@ -264,7 +293,7 @@ export const SharingDialog: React.FC = ({
- {activeTab === "Share to space" ? ( + {activeTab === "Share" ? ( <>