Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Password protection for videos + Player UI tweaks (#571)

Richie McIlroya974cf10fcf7
diff --git a/apps/web/actions/videos/password.ts b/apps/web/actions/videos/password.ts
new file mode 100644
index 000000000..03b8b5ce3
--- /dev/null
+++ b/apps/web/actions/videos/password.ts
@@ -0,0 +1,101 @@
+"use server";
+
+import { getCurrentUser } from "@cap/database/auth/session";
+import { videos } from "@cap/database/schema";
+import { db } from "@cap/database";
+import { eq } from "drizzle-orm";
+import { encrypt, hashPassword, verifyPassword } from "@cap/database/crypto";
+import { revalidatePath } from "next/cache";
+import { cookies } from "next/headers";
+
+export async function setVideoPassword(videoId: string, password: string) {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user || !videoId || typeof password !== "string") {
+ throw new Error("Missing required data");
+ }
+
+ const [video] = await db()
+ .select()
+ .from(videos)
+ .where(eq(videos.id, videoId));
+
+ if (!video || video.ownerId !== user.id) {
+ throw new Error("Unauthorized");
+ }
+
+ const hashed = await hashPassword(password);
+ await db()
+ .update(videos)
+ .set({ password: hashed })
+ .where(eq(videos.id, videoId));
+
+ revalidatePath("/dashboard/caps");
+ revalidatePath("/dashboard/shared-caps");
+ revalidatePath(`/s/${videoId}`);
+
+ return { success: true, value: "Password updated successfully" };
+ } catch (error) {
+ console.error("Error setting video password:", error);
+ return { success: false, error: "Failed to update password" };
+ }
+}
+
+export async function removeVideoPassword(videoId: string) {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user || !videoId) {
+ throw new Error("Missing required data");
+ }
+
+ const [video] = await db()
+ .select()
+ .from(videos)
+ .where(eq(videos.id, videoId));
+
+ if (!video || video.ownerId !== user.id) {
+ throw new Error("Unauthorized");
+ }
+
+ await db()
+ .update(videos)
+ .set({ password: null })
+ .where(eq(videos.id, videoId));
+
+ revalidatePath("/dashboard/caps");
+ revalidatePath("/dashboard/shared-caps");
+ revalidatePath(`/s/${videoId}`);
+
+ return { success: true, value: "Password removed successfully" };
+ } catch (error) {
+ console.error("Error removing video password:", error);
+ return { success: false, error: "Failed to remove password" };
+ }
+}
+
+export async function verifyVideoPassword(videoId: string, password: string) {
+ try {
+ if (!videoId || typeof password !== "string")
+ throw new Error("Missing data");
+
+ const [video] = await db()
+ .select()
+ .from(videos)
+ .where(eq(videos.id, videoId));
+
+ if (!video || !video.password) throw new Error("No password set");
+
+ const valid = await verifyPassword(video.password, password);
+
+ if (!valid) throw new Error("Invalid password");
+
+ cookies().set("x-cap-password", await encrypt(video.password));
+
+ return { success: true, value: "Password verified" };
+ } catch (error) {
+ console.error("Error verifying video password:", error);
+ return { success: false, error: "Failed to verify password" };
+ }
+}
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 4b8f068c9..1ca821d58 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -22,6 +22,7 @@ type VideoData = {
sharedOrganizations: { id: string; name: string }[];
ownerName: string;
metadata?: VideoMetadata
+ hasPassword: boolean;
}[];
export const Caps = ({
diff --git a/apps/web/app/dashboard/caps/components/CapCard.tsx b/apps/web/app/dashboard/caps/components/CapCard.tsx
index c1c7ed04b..052c9b3d1 100644
--- a/apps/web/app/dashboard/caps/components/CapCard.tsx
+++ b/apps/web/app/dashboard/caps/components/CapCard.tsx
@@ -3,9 +3,9 @@ import { editTitle } from "@/actions/videos/edit-title";
import { useSharedContext } from "@/app/dashboard/_components/DynamicSharedLayout";
import { CapCardAnalytics } from "@/app/dashboard/caps/components/CapCardAnalytics";
import { SharingDialog } from "@/app/dashboard/caps/components/SharingDialog";
+import { PasswordDialog } from "@/app/dashboard/caps/components/PasswordDialog";
import { Tooltip } from "@/components/Tooltip";
import { VideoThumbnail } from "@/components/VideoThumbnail";
-import { usePublicEnv } from "@/utils/public-env";
import { VideoMetadata } from "@cap/database/types";
import { buildEnv, NODE_ENV } from "@cap/env";
import { Button } from "@cap/ui";
@@ -14,6 +14,8 @@ import {
faChevronDown,
faLink,
faTrash,
+ faLock,
+ faUnlock,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
@@ -34,6 +36,7 @@ interface Props extends PropsWithChildren {
sharedOrganizations?: { id: string; name: string; iconUrl?: string }[];
ownerName: string | null;
metadata?: VideoMetadata;
+ hasPassword?: boolean;
};
analytics: number;
onDelete?: (videoId: string) => Promise<void>;
@@ -64,6 +67,10 @@ export const CapCard = ({
const [isEditing, setIsEditing] = useState(false);
const [title, setTitle] = useState(cap.name);
const [isSharingDialogOpen, setIsSharingDialogOpen] = useState(false);
+ const [isPasswordDialogOpen, setIsPasswordDialogOpen] = useState(false);
+ const [passwordProtected, setPasswordProtected] = useState(
+ cap.hasPassword || false
+ );
const [, setSharedOrganizations] = useState(cap.sharedOrganizations);
const [isDateEditing, setIsDateEditing] = useState(false);
const [copyPressed, setCopyPressed] = useState(false);
@@ -72,7 +79,7 @@ export const CapCard = ({
);
const [showFullDate, setShowFullDate] = useState(false);
const router = useRouter();
- const { activeOrganization } = useSharedContext();
+ const { isSubscribed, setUpgradeModalOpen } = useSharedContext();
const handleTitleBlur = async (capName: string) => {
if (!title || capName === title) {
@@ -108,6 +115,11 @@ export const CapCard = ({
router.refresh();
};
+ const handlePasswordUpdated = (protectedStatus: boolean) => {
+ setPasswordProtected(protectedStatus);
+ router.refresh();
+ };
+
const isOwner = userId === cap.ownerId;
const renderSharedStatus = () => {
@@ -241,16 +253,6 @@ export const CapCard = ({
}
};
- const { webUrl } = usePublicEnv();
-
- const capUrl =
- activeOrganization?.organization.customDomain &&
- activeOrganization?.organization.domainVerified
- ? `https://${activeOrganization.organization.customDomain}/s/${cap.id}`
- : buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"
- ? `https://cap.link/${cap.id}`
- : `${webUrl}/s/${cap.id}`;
-
return (
<>
<SharingDialog
@@ -262,6 +264,13 @@ export const CapCard = ({
userOrganizations={userOrganizations}
onSharingUpdated={handleSharingUpdated}
/>
+ <PasswordDialog
+ isOpen={isPasswordDialogOpen}
+ onClose={() => setIsPasswordDialogOpen(false)}
+ videoId={cap.id}
+ hasPassword={passwordProtected}
+ onPasswordUpdated={handlePasswordUpdated}
+ />
<div
onClick={handleCardClick}
className={clsx(
@@ -293,7 +302,11 @@ export const CapCard = ({
<Button
onClick={(e) => {
e.stopPropagation();
- handleCopy(capUrl);
+ handleCopy(
+ buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"
+ ? `https://cap.link/${cap.id}`
+ : `${location.origin}/s/${cap.id}`
+ );
}}
className="!size-8 delay-0 hover:opacity-80 rounded-full min-w-fit !p-0"
variant="white"
@@ -322,6 +335,32 @@ export const CapCard = ({
)}
</Button>
</Tooltip>
+ <Tooltip
+ content={
+ passwordProtected ? "Edit password" : "Add password to access"
+ }
+ >
+ <Button
+ onClick={(e) => {
+ e.stopPropagation();
+ if (!isSubscribed) {
+ setUpgradeModalOpen(true);
+ } else {
+ setIsPasswordDialogOpen(true);
+ }
+ }}
+ className="!size-8 delay-50 hover:opacity-80 rounded-full min-w-fit !p-0"
+ variant="white"
+ size="sm"
+ >
+ <FontAwesomeIcon
+ className={`size-3 ${
+ passwordProtected ? "text-amber-600" : "text-gray-12"
+ }`}
+ icon={passwordProtected ? faLock : faUnlock}
+ />
+ </Button>
+ </Tooltip>
<Tooltip content="Delete Cap">
<Button
onClick={(e) => {
@@ -417,10 +456,10 @@ export const CapCard = ({
</p>
)}
</div>
+
{renderSharedStatus()}
<div className="mb-1 h-[1.5rem]">
{" "}
- {/* Fixed height container */}
{isDateEditing && !sharedCapCard ? (
<div className="flex items-center h-full">
<input
diff --git a/apps/web/app/dashboard/caps/components/PasswordDialog.tsx b/apps/web/app/dashboard/caps/components/PasswordDialog.tsx
new file mode 100644
index 000000000..88bc44330
--- /dev/null
+++ b/apps/web/app/dashboard/caps/components/PasswordDialog.tsx
@@ -0,0 +1,118 @@
+"use client";
+
+import {
+ Button,
+ Dialog,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Input,
+} from "@cap/ui";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { faLock } from "@fortawesome/free-solid-svg-icons";
+import { useState } from "react";
+import { toast } from "sonner";
+import { useMutation } from "@tanstack/react-query";
+import {
+ setVideoPassword,
+ removeVideoPassword,
+} from "@/actions/videos/password";
+
+interface PasswordDialogProps {
+ isOpen: boolean;
+ onClose: () => void;
+ videoId: string;
+ hasPassword: boolean;
+ onPasswordUpdated: (protectedStatus: boolean) => void;
+}
+
+export const PasswordDialog: React.FC<PasswordDialogProps> = ({
+ isOpen,
+ onClose,
+ videoId,
+ hasPassword,
+ onPasswordUpdated,
+}) => {
+ const [password, setPassword] = useState("");
+
+ const updatePassword = useMutation({
+ mutationFn: () =>
+ setVideoPassword(videoId, password).then((v) => {
+ if (v.success) return v.value;
+ throw new Error(v.error);
+ }),
+ onSuccess: (result) => {
+ toast.success(result);
+ onPasswordUpdated(true);
+ onClose();
+ },
+ onError: (e) => {
+ toast.error(e.message);
+ },
+ });
+
+ const removePassword = useMutation({
+ mutationFn: () =>
+ removeVideoPassword(videoId).then((v) => {
+ if (v.success) return v.value;
+ throw new Error(v.error);
+ }),
+ onSuccess: (result) => {
+ toast.success(result);
+ onPasswordUpdated(false);
+ onClose();
+ },
+ onError: (e) => {
+ toast.error(e.message);
+ },
+ });
+
+ const pending = removePassword.isPending || updatePassword.isPending;
+
+ return (
+ <Dialog open={isOpen} onOpenChange={onClose}>
+ <DialogContent className="p-0 w-full max-w-sm rounded-xl border bg-gray-2 border-gray-4">
+ <DialogHeader
+ icon={<FontAwesomeIcon icon={faLock} className="size-3.5" />}
+ description={
+ hasPassword
+ ? "Update or remove the password for this video"
+ : "Restrict access to this video with a password"
+ }
+ >
+ <DialogTitle>Password Protection</DialogTitle>
+ </DialogHeader>
+ <div className="p-5 space-y-4">
+ <Input
+ type="password"
+ placeholder={hasPassword ? "Enter new password" : "Password"}
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ />
+ </div>
+ <DialogFooter className="p-5 border-t border-gray-4">
+ {hasPassword && (
+ <Button
+ size="sm"
+ variant="destructive"
+ onClick={() => removePassword.mutate()}
+ disabled={pending}
+ >
+ Remove
+ </Button>
+ )}
+ <Button
+ size="sm"
+ variant="dark"
+ onClick={() => updatePassword.mutate()}
+ spinner={pending}
+ disabled={pending}
+ >
+ Save
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/apps/web/app/dashboard/caps/page.tsx b/apps/web/app/dashboard/caps/page.tsx
index a93ec8758..f655a57e5 100644
--- a/apps/web/app/dashboard/caps/page.tsx
+++ b/apps/web/app/dashboard/caps/page.tsx
@@ -74,6 +74,7 @@ export default async function CapsPage({
${videos.createdAt}
)
`,
+ hasPassword: sql<number>`IF(${videos.password} IS NULL, 0, 1)`,
})
.from(videos)
.leftJoin(comments, eq(videos.id, comments.videoId))
@@ -126,6 +127,7 @@ export default async function CapsPage({
[key: string]: any;
}
| undefined,
+ hasPassword: video.hasPassword === 1,
};
});
diff --git a/apps/web/app/dashboard/settings/organization/components/InviteDialog.tsx b/apps/web/app/dashboard/settings/organization/components/InviteDialog.tsx
index d1900a385..bf096da19 100644
--- a/apps/web/app/dashboard/settings/organization/components/InviteDialog.tsx
+++ b/apps/web/app/dashboard/settings/organization/components/InviteDialog.tsx
@@ -17,6 +17,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
+import { useMutation } from "@tanstack/react-query";
interface InviteDialogProps {
isOpen: boolean;
@@ -37,7 +38,6 @@ export const InviteDialog = ({
const { activeOrganization } = useSharedContext();
const [inviteEmails, setInviteEmails] = useState<string[]>([]);
const [emailInput, setEmailInput] = useState("");
- const [inviteLoading, setInviteLoading] = useState(false);
const [upgradeLoading, setUpgradeLoading] = useState(false);
const { inviteQuota, remainingSeats } = calculateSeats(
@@ -80,35 +80,38 @@ export const InviteDialog = ({
}
};
- const handleSendInvites = async () => {
- if (!isOwner) {
- showOwnerToast();
- return;
- }
+ const sendInvites = useMutation({
+ mutationFn: async () => {
+ if (!isOwner) {
+ showOwnerToast();
+ throw new Error("Not authorized");
+ }
- if (inviteEmails.length > remainingSeats) {
- toast.error(
- `Not enough seats available. You have ${remainingSeats} seats remaining.`
- );
- return;
- }
+ if (inviteEmails.length > remainingSeats) {
+ throw new Error(
+ `Not enough seats available. You have ${remainingSeats} seats remaining.`
+ );
+ }
- try {
- setInviteLoading(true);
- await sendOrganizationInvites(
+ return await sendOrganizationInvites(
inviteEmails,
activeOrganization?.organization.id as string
);
+ },
+ onSuccess: () => {
toast.success("Invites sent successfully");
setInviteEmails([]);
setIsOpen(false);
router.refresh();
- } catch (error) {
+ },
+ onError: (error) => {
console.error("Error sending invites:", error);
- toast.error("An error occurred while sending invites");
- } finally {
- setInviteLoading(false);
- }
+ toast.error(error instanceof Error ? error.message : "An error occurred while sending invites");
+ },
+ });
+
+ const handleSendInvites = () => {
+ sendInvites.mutate();
};
return (
@@ -200,9 +203,9 @@ export const InviteDialog = ({
type="button"
size="sm"
variant="dark"
- spinner={inviteLoading}
+ spinner={sendInvites.isPending}
disabled={
- inviteLoading || inviteEmails.length === 0 || remainingSeats === 0
+ sendInvites.isPending || inviteEmails.length === 0 || remainingSeats === 0
}
onClick={handleSendInvites}
>
diff --git a/apps/web/app/providers.tsx b/apps/web/app/providers.tsx
index 1a258aad8..cb05cccc2 100644
--- a/apps/web/app/providers.tsx
+++ b/apps/web/app/providers.tsx
@@ -8,6 +8,7 @@ import { buildEnv } from "@cap/env";
import PostHogPageView from "./PosthogPageView";
import Intercom from "@intercom/messenger-js-sdk";
import { usePathname } from "next/navigation";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
export function PostHogProvider({
children,
@@ -107,6 +108,8 @@ export function AnalyticsProvider({
return <>{children}</>;
}
+const queryClient = new QueryClient();
+
export function Providers({
children,
userId,
@@ -121,13 +124,15 @@ export function Providers({
email?: string;
}) {
return (
- <AnalyticsProvider
- userId={userId}
- intercomHash={intercomHash}
- name={name}
- email={email}
- >
- {children}
- </AnalyticsProvider>
+ <QueryClientProvider client={queryClient}>
+ <AnalyticsProvider
+ userId={userId}
+ intercomHash={intercomHash}
+ name={name}
+ email={email}
+ >
+ {children}
+ </AnalyticsProvider>
+ </QueryClientProvider>
);
}
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index e5d8dc1f9..cde1a0a3d 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -9,6 +9,7 @@ import { ShareHeader } from "./_components/ShareHeader";
import { ShareVideo } from "./_components/ShareVideo";
import { Sidebar } from "./_components/Sidebar";
import { Toolbar } from "./_components/Toolbar";
+import { PasswordOverlay } from "./_components/PasswordOverlay";
const formatTime = (time: number) => {
const minutes = Math.floor(time / 60);
@@ -26,6 +27,7 @@ type VideoWithOrganizationInfo = typeof videos.$inferSelect & {
organizationMembers?: string[];
organizationId?: string;
sharedOrganizations?: { id: string; name: string }[];
+ hasPassword?: boolean;
};
interface ShareProps {
@@ -72,12 +74,6 @@ export const Share: React.FC<ShareProps> = ({
data.transcriptionStatus || null
);
- useEffect(() => {
- if (initialAiData) {
- } else {
- }
- }, [initialAiData]);
-
const [aiData, setAiData] = useState<{
title?: string | null;
summary?: string | null;
@@ -265,7 +261,7 @@ export const Share: React.FC<ShareProps> = ({
: { ...data, createdAt: effectiveDate };
return (
- <div className="min-h-screen flex flex-col bg-[#F7F8FA]">
+ <>
<div className="container flex-1 px-4 py-4 mx-auto">
<ShareHeader
data={headerData}
@@ -395,7 +391,6 @@ export const Share: React.FC<ShareProps> = ({
</div>
</div>
</div>
-
<div className="py-4 mt-auto">
<a
target="_blank"
@@ -406,6 +401,6 @@ export const Share: React.FC<ShareProps> = ({
<Logo className="w-14 h-auto" />
</a>
</div>
- </div>
+ </>
);
};
diff --git a/apps/web/app/s/[videoId]/_components/PasswordOverlay.tsx b/apps/web/app/s/[videoId]/_components/PasswordOverlay.tsx
new file mode 100644
index 000000000..ae9e82897
--- /dev/null
+++ b/apps/web/app/s/[videoId]/_components/PasswordOverlay.tsx
@@ -0,0 +1,104 @@
+"use client";
+
+import {
+ Button,
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ Input,
+ Logo,
+} from "@cap/ui";
+import { motion } from "framer-motion";
+import { useState } from "react";
+import { toast } from "sonner";
+import { verifyVideoPassword } from "@/actions/videos/password";
+import { useMutation } from "@tanstack/react-query";
+import { useRouter } from "next/navigation";
+
+interface PasswordOverlayProps {
+ isOpen: boolean;
+ videoId: string;
+}
+
+const MotionDialogContent = motion.create(DialogContent);
+
+export const PasswordOverlay: React.FC<PasswordOverlayProps> = ({
+ isOpen,
+ videoId,
+}) => {
+ const [password, setPassword] = useState("");
+ const router = useRouter();
+
+ const verifyPassword = useMutation({
+ mutationFn: () =>
+ verifyVideoPassword(videoId, password).then((v) => {
+ if (v.success) return v.value;
+ throw new Error(v.error);
+ }),
+ onSuccess: (result) => {
+ toast.success(result);
+ router.refresh();
+ },
+ onError: (e) => {
+ toast.error(e.message);
+ },
+ });
+
+ return (
+ <Dialog open={isOpen}>
+ <MotionDialogContent
+ // initial={{ opacity: 0, scale: 0.95 }}
+ // animate={{ opacity: 1, scale: 1 }}
+ // exit={{ opacity: 0, scale: 0.95 }}
+ // transition={{ duration: 0.2 }}
+ className="w-[90vw] sm:max-w-md p-8 rounded-xl border border-gray-200 bg-white shadow-xl"
+ >
+ <div className="flex flex-col items-center space-y-6">
+ <div className="flex flex-col items-center space-y-4">
+ <Logo className="w-24 h-auto" />
+ <div className="text-center space-y-2">
+ <h2 className="text-xl font-semibold text-gray-12">
+ Protected Video
+ </h2>
+ <p className="text-sm text-gray-10 max-w-sm">
+ This video is password protected. Please enter the password to
+ continue watching.
+ </p>
+ </div>
+ </div>
+
+ <div className="w-full space-y-4">
+ <div className="space-y-2">
+ <label
+ htmlFor="password"
+ className="text-sm font-medium text-gray-12"
+ >
+ Password
+ </label>
+ <Input
+ id="password"
+ type="password"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ placeholder="Enter password"
+ className="w-full"
+ autoFocus
+ />
+ </div>
+ <Button
+ type="button"
+ variant="dark"
+ size="lg"
+ className="w-full"
+ spinner={verifyPassword.isPending}
+ disabled={verifyPassword.isPending || !password.trim()}
+ onClick={() => verifyPassword.mutate()}
+ >
+ {verifyPassword.isPending ? "Verifying..." : "Access Video"}
+ </Button>
+ </div>
+ </div>
+ </MotionDialogContent>
+ </Dialog>
+ );
+};
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index 730b61d97..8147beca9 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -2,7 +2,11 @@ import { Button } from "@cap/ui";
import { videos } from "@cap/database/schema";
import moment from "moment";
import { userSelectProps } from "@cap/database/auth/session";
-import { faChevronDown } from "@fortawesome/free-solid-svg-icons";
+import {
+ faChevronDown,
+ faLock,
+ faUnlock,
+} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useRouter } from "next/navigation";
import { useState, useEffect } from "react";
@@ -182,16 +186,24 @@ export const ShareHeader = ({
{user !== null && (
<div className="flex space-x-2">
<div>
- <Button
- variant="white"
- onClick={() => {
- navigator.clipboard.writeText(getVideoLink());
- toast.success("Link copied to clipboard!");
- }}
- >
- {getDisplayLink()}
- <Copy className="ml-2 w-4 h-4" />
- </Button>
+ <div className="flex items-center gap-2">
+ {data.password && (
+ <FontAwesomeIcon
+ className="size-4 text-amber-600"
+ icon={faLock}
+ />
+ )}
+ <Button
+ variant="white"
+ onClick={() => {
+ navigator.clipboard.writeText(getVideoLink());
+ toast.success("Link copied to clipboard!");
+ }}
+ >
+ {getDisplayLink()}
+ <Copy className="ml-2 w-4 h-4" />
+ </Button>
+ </div>
{user !== null && !isUserPro && (
<button
className="flex items-center mt-1 text-sm text-gray-400 cursor-pointer hover:text-blue-500"
diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
index f133c4ae3..d8bbc4ba6 100644
--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx
@@ -43,6 +43,15 @@ const formatTime = (time: number) => {
.padStart(2, "0")}`;
};
+const formatTimeWithMilliseconds = (time: number) => {
+ const minutes = Math.floor(time / 60);
+ const seconds = Math.floor(time % 60);
+ const milliseconds = Math.floor((time % 1) * 100);
+ return `${minutes.toString().padStart(2, "0")}:${seconds
+ .toString()
+ .padStart(2, "0")}.${milliseconds.toString().padStart(2, "0")}`;
+};
+
type CommentWithAuthor = typeof commentsSchema.$inferSelect & {
authorName: string | null;
};
@@ -81,8 +90,8 @@ export const ShareVideo = forwardRef<
const [previewTime, setPreviewTime] = useState(0);
const [previewPosition, setPreviewPosition] = useState(0);
const [previewLoaded, setPreviewLoaded] = useState(false);
- const [previewWidth, setPreviewWidth] = useState(160);
- const [previewHeight, setPreviewHeight] = useState(90);
+ const [previewWidth, setPreviewWidth] = useState(200);
+ const [previewHeight, setPreviewHeight] = useState(112);
const [isMP4Source, setIsMP4Source] = useState(false);
const [thumbnailUrl, setThumbnailUrl] = useState<string | null>(null);
@@ -90,6 +99,7 @@ export const ShareVideo = forwardRef<
const [isHoveringVideo, setIsHoveringVideo] = useState(false);
const [isHoveringControls, setIsHoveringControls] = useState(false);
const hideControlsTimeoutRef = useRef<NodeJS.Timeout | null>(null);
+ const [userMuted, setUserMuted] = useState(false);
const [scrubbingVideo, setScrubbingVideo] = useState<HTMLVideoElement | null>(
null
@@ -255,26 +265,6 @@ export const ShareVideo = forwardRef<
setVideoMetadataLoaded(true);
setVideoReadyToPlay(true);
- setIsPlaying(true);
- if (videoRef.current) {
- videoRef.current.play().catch((error) => {
- console.error("Error auto-playing video:", error);
- setIsPlaying(false);
- });
- }
-
- if (isPlaying && videoRef.current) {
- const currentPosition = videoRef.current.currentTime;
-
- videoRef.current.play().catch((error) => {
- console.error("Error playing video in onCanPlay:", error);
- });
-
- if (videoRef.current.currentTime === 0 && currentPosition > 0) {
- videoRef.current.currentTime = currentPosition;
- }
- }
-
setTimeout(() => {
setIsLoading(false);
}, 100);
@@ -310,7 +300,9 @@ export const ShareVideo = forwardRef<
if (!videoReadyToPlay) {
setIsPlaying(true);
} else {
- videoElement.muted = false;
+ if (!userMuted) {
+ videoElement.muted = false;
+ }
const currentPosition = videoElement.currentTime;
@@ -334,9 +326,11 @@ export const ShareVideo = forwardRef<
.play()
.then(() => {
setIsPlaying(true);
- setTimeout(() => {
- videoElement.muted = false;
- }, 100);
+ if (!userMuted) {
+ setTimeout(() => {
+ videoElement.muted = false;
+ }, 100);
+ }
if (
videoElement.currentTime === 0 &&
@@ -373,8 +367,27 @@ export const ShareVideo = forwardRef<
return;
}
const validTime = Math.max(0, Math.min(time, longestDuration));
- if (videoRef.current) videoRef.current.currentTime = validTime;
- setCurrentTime(validTime);
+
+ if (videoRef.current && videoRef.current.readyState >= 2) {
+ try {
+ const video = videoRef.current;
+ video.currentTime = validTime;
+
+ const handleSeeked = () => {
+ setCurrentTime(video.currentTime);
+ video.removeEventListener("seeked", handleSeeked);
+ };
+
+ video.addEventListener("seeked", handleSeeked);
+
+ setTimeout(() => {
+ video.removeEventListener("seeked", handleSeeked);
+ setCurrentTime(validTime);
+ }, 1000);
+ } catch (error) {
+ console.error("Error setting video currentTime:", error);
+ }
+ }
};
useEffect(() => {
@@ -397,20 +410,16 @@ export const ShareVideo = forwardRef<
if (!videoElement || !videoReadyToPlay) return;
if (isPlaying) {
- const currentPosition = videoElement.currentTime;
-
- videoElement.play().catch((error) => {
- console.error("Error playing video", error);
- setIsPlaying(false);
- });
-
- if (videoElement.currentTime === 0 && currentPosition > 0) {
- videoElement.currentTime = currentPosition;
+ if (!seeking) {
+ videoElement.play().catch((error) => {
+ console.error("Error playing video", error);
+ setIsPlaying(false);
+ });
}
} else {
videoElement.pause();
}
- }, [isPlaying, videoReadyToPlay]);
+ }, [isPlaying, videoReadyToPlay, seeking]);
useEffect(() => {
const handleSeeking = () => {
@@ -676,8 +685,16 @@ export const ShareVideo = forwardRef<
};
const calculateNewTime = (event: any, seekBar: any) => {
+ if (!longestDuration || longestDuration <= 0) {
+ return 0;
+ }
+
const rect = seekBar.getBoundingClientRect();
+ if (rect.width <= 0) {
+ return 0;
+ }
+
let clientX = 0;
if (event.touches && event.touches.length > 0) {
clientX = event.touches[0].clientX;
@@ -687,12 +704,18 @@ export const ShareVideo = forwardRef<
const offsetX = Math.max(0, Math.min(clientX - rect.left, rect.width));
const relativePosition = offsetX / rect.width;
- const newTime = relativePosition * longestDuration;
+ const newTime = Math.max(
+ 0,
+ Math.min(relativePosition * longestDuration, longestDuration)
+ );
+
return newTime;
};
const handleSeekMouseDown = () => {
- setSeeking(true);
+ if (videoRef.current && videoRef.current.readyState >= 2) {
+ setSeeking(true);
+ }
};
const handleSeekMouseUp = (
@@ -703,11 +726,15 @@ export const ShareVideo = forwardRef<
setSeeking(false);
const seekBar = event.currentTarget;
const seekTo = calculateNewTime(event, seekBar);
- if (!isTouch) {
- applyTimeToVideos(seekTo);
- }
- if (isPlaying) {
- videoRef.current?.play();
+
+ applyTimeToVideos(seekTo);
+
+ if (isPlaying && videoRef.current) {
+ setTimeout(() => {
+ videoRef.current?.play().catch((error) => {
+ console.error("Error resuming playback after seek:", error);
+ });
+ }, 100);
}
setShowPreview(false);
};
@@ -717,7 +744,10 @@ export const ShareVideo = forwardRef<
const seekBar = event.currentTarget;
const seekTo = calculateNewTime(event, seekBar);
- applyTimeToVideos(seekTo);
+
+ if (Math.abs(seekTo - currentTime) > 0.1) {
+ applyTimeToVideos(seekTo);
+ }
};
const handleTimelineLeave = () => {
@@ -729,7 +759,9 @@ export const ShareVideo = forwardRef<
const handleMuteClick = () => {
if (videoRef.current) {
- videoRef.current.muted = videoRef.current.muted ? false : true;
+ const newMutedState = !videoRef.current.muted;
+ videoRef.current.muted = newMutedState;
+ setUserMuted(newMutedState);
}
};
@@ -1064,41 +1096,77 @@ export const ShareVideo = forwardRef<
{showPreview && !isLoading && isMP4Source && isLargeScreen && (
<div
- className="hidden overflow-hidden absolute z-30 bg-black rounded-md border border-gray-700 shadow-lg transition-opacity duration-150 xl:block"
+ className="hidden absolute z-30 transition-opacity duration-150 xl:block"
style={{
left: `${previewPosition}px`,
- bottom: "70px",
- width: `${previewWidth}px`,
- height: `${previewHeight}px`,
+ bottom: "80px",
opacity: previewLoaded ? 1 : 0.7,
}}
>
- {thumbnailUrl ? (
- <img
- src={thumbnailUrl}
- alt={`Preview at ${formatTime(previewTime)}`}
- className="object-contain w-full h-full bg-black"
- onError={() => {
- setThumbnailUrl(null);
- }}
- />
- ) : (
- <canvas
- ref={previewCanvasRef}
- className="object-contain w-full h-full bg-black"
- />
- )}
- {!thumbnailUrl && (
- <div className="absolute right-0 bottom-0 left-0 px-2 py-1 text-xs text-center text-white bg-black bg-opacity-70">
- {formatTime(previewTime)}
+ <div className="flex flex-col items-center">
+ <div
+ style={{ boxShadow: "0 0 100px rgba(0, 0, 0, 0.75)" }}
+ className="bg-black rounded-lg border border-gray-600 overflow-hidden"
+ >
+ <div
+ className="bg-black"
+ style={{
+ width: `${previewWidth}px`,
+ height: `${previewHeight}px`,
+ }}
+ >
+ {thumbnailUrl ? (
+ <img
+ src={thumbnailUrl}
+ alt={`Preview at ${formatTime(previewTime)}`}
+ className="object-contain w-full h-full bg-black"
+ onError={() => {
+ setThumbnailUrl(null);
+ }}
+ />
+ ) : (
+ <canvas
+ ref={previewCanvasRef}
+ className="object-contain w-full h-full bg-black"
+ />
+ )}
+ </div>
</div>
- )}
+ <div className="mt-2 text-center space-y-0.5">
+ {chapters.length > 0 && longestDuration > 0 && (
+ <div
+ className="text-sm text-white font-medium leading-tight"
+ style={{ textShadow: "0 0 3px rgba(0, 0, 0, 0.7)" }}
+ >
+ {(() => {
+ const previewChapter = chapters.find((chapter, index) => {
+ const nextChapter = chapters[index + 1];
+ const chapterStart = chapter.start;
+ const chapterEnd = nextChapter
+ ? nextChapter.start
+ : longestDuration;
+ return (
+ previewTime >= chapterStart && previewTime < chapterEnd
+ );
+ });
+ return previewChapter ? previewChapter.title : "";
+ })()}
+ </div>
+ )}
+ <div
+ className="text-sm text-white font-medium"
+ style={{ textShadow: "0 0 3px rgba(0, 0, 0, 0.7)" }}
+ >
+ {formatTimeWithMilliseconds(previewTime)}
+ </div>
+ </div>
+ </div>
</div>
)}
<div
className={`absolute left-0 right-0 z-30 transition-all duration-300 ease-in-out ${
- overlayVisible ? "bottom-[60px]" : "bottom-1"
+ overlayVisible ? "bottom-[40px] md:bottom-[60px]" : "bottom-1"
}`}
>
<div
@@ -1123,7 +1191,7 @@ export const ShareVideo = forwardRef<
onTouchEnd={(e) => handleSeekMouseUp(e, true)}
>
{!isLoading && comments !== null && (
- <div className="-mt-7 w-full md:-mt-6">
+ <div className="-mt-6 w-full md:-mt-6">
{comments.map((comment) => {
const commentPosition =
comment.timestamp === null
@@ -1146,7 +1214,7 @@ export const ShareVideo = forwardRef<
return (
<div
key={comment.id}
- className="absolute z-10 text-sm transition-all hover:scale-125"
+ className="absolute z-10 text-sm transition-all hover:scale-125 -mt-5 md:-mt-5"
style={{
left: `${commentPosition}%`,
}}
@@ -1175,14 +1243,72 @@ export const ShareVideo = forwardRef<
onMouseMove={handleTimelineHover}
onMouseLeave={handleTimelineLeave}
>
- <div
- style={{ boxShadow: "0 0 20px rgba(0,0,0,0.6)" }}
- className="absolute top-2.5 w-full h-1 sm:h-1.5 bg-gray-400 bg-opacity-50 z-10"
- />
- <div
- className="absolute top-2.5 h-1 sm:h-1.5 bg-white cursor-pointer z-10"
- style={{ width: `${watchedPercentage}%` }}
- />
+ {chapters.length > 0 && longestDuration > 0 ? (
+ <div className="absolute top-2.5 w-full h-1 sm:h-1.5 z-10 flex">
+ {chapters.map((chapter, index) => {
+ const nextChapter = chapters[index + 1];
+ const chapterStart = chapter.start;
+ const chapterEnd = nextChapter
+ ? nextChapter.start
+ : longestDuration;
+ const chapterDuration = chapterEnd - chapterStart;
+ const chapterWidth =
+ (chapterDuration / longestDuration) * 100;
+
+ const chapterProgress = Math.max(
+ 0,
+ Math.min((currentTime - chapterStart) / chapterDuration, 1)
+ );
+
+ const isCurrentChapter =
+ currentTime >= chapterStart && currentTime < chapterEnd;
+
+ return (
+ <div
+ key={chapter.start}
+ className="relative h-full cursor-pointer group"
+ style={{ width: `${chapterWidth}%` }}
+ onClick={(e) => {
+ e.stopPropagation();
+ applyTimeToVideos(chapter.start);
+ }}
+ >
+ <div
+ className="w-full h-full bg-gray-400 bg-opacity-50 group-hover:bg-opacity-70 transition-colors"
+ style={{
+ boxShadow: "0 0 20px rgba(0,0,0,0.6)",
+ borderRight:
+ index < chapters.length - 1
+ ? "1px solid rgba(255,255,255,0.3)"
+ : "none",
+ }}
+ />
+ {isCurrentChapter && (
+ <div
+ className="absolute top-0 left-0 h-full bg-white transition-all duration-100"
+ style={{ width: `${chapterProgress * 100}%` }}
+ />
+ )}
+ {currentTime > chapterEnd && (
+ <div className="absolute top-0 left-0 w-full h-full bg-white" />
+ )}
+ </div>
+ );
+ })}
+ </div>
+ ) : (
+ <>
+ <div
+ style={{ boxShadow: "0 0 20px rgba(0,0,0,0.6)" }}
+ className="absolute top-2.5 w-full h-1 sm:h-1.5 bg-gray-400 bg-opacity-50 z-10"
+ />
+ <div
+ className="absolute top-2.5 h-1 sm:h-1.5 bg-white cursor-pointer z-10"
+ style={{ width: `${watchedPercentage}%` }}
+ />
+ </>
+ )}
+
<div
style={{
boxShadow: "0 0 20px rgba(0,0,0,0.1)",
@@ -1197,43 +1323,11 @@ export const ShareVideo = forwardRef<
tabIndex={0}
/>
</div>
-
- {chapters.length > 0 && longestDuration > 0 && (
- <div
- className={`-mt-10 w-full md:-mt-10 pointer-events-none transition-opacity duration-300 ${
- overlayVisible ? "opacity-100" : "opacity-0"
- }`}
- >
- {chapters.map((ch) => {
- const pos = (ch.start / longestDuration) * 100;
- return (
- <div
- key={ch.start}
- className="absolute z-50 -translate-x-1/2 cursor-pointer pointer-events-auto"
- style={{ left: `${pos}%` }}
- data-tooltip-id={`chapter-${ch.start}`}
- data-tooltip-content={ch.title}
- onClick={(e) => {
- e.stopPropagation();
- applyTimeToVideos(ch.start);
- }}
- >
- <div className="w-4 h-4 bg-white bg-opacity-70 rounded-full hover:bg-opacity-100 hover:scale-125 transition-all duration-200 border-2 border-gray-10" />
- <Tooltip
- id={`chapter-${ch.start}`}
- place="top"
- className="z-50"
- />
- </div>
- );
- })}
- </div>
- )}
</div>
</div>
<div
- className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 z-20 transition-transform duration-300 ease-in-out ${
+ className={`absolute bottom-0 left-0 right-0 bg-black bg-opacity-60 z-20 transition-transform duration-300 ease-in-out ${
overlayVisible ? "translate-y-0" : "translate-y-full"
}`}
onMouseEnter={() => {
@@ -1260,8 +1354,27 @@ export const ShareVideo = forwardRef<
)}
</button>
</span>
- <div className="text-xs sm:text-sm text-white font-medium select-none tabular text-clip overflow-hidden whitespace-nowrap space-x-0.5">
- {formatTime(currentTime)} - {formatTime(longestDuration)}
+ <div className="flex items-center space-x-2">
+ <div className="text-xs sm:text-sm text-white font-medium select-none tabular text-clip overflow-hidden whitespace-nowrap">
+ {formatTime(currentTime)} - {formatTime(longestDuration)}
+ </div>
+ {chapters.length > 0 && longestDuration > 0 && (
+ <div className="hidden sm:block text-xs sm:text-sm text-gray-200 font-medium select-none text-clip overflow-hidden whitespace-nowrap max-w-[200px]">
+ {(() => {
+ const currentChapter = chapters.find((chapter, index) => {
+ const nextChapter = chapters[index + 1];
+ const chapterStart = chapter.start;
+ const chapterEnd = nextChapter
+ ? nextChapter.start
+ : longestDuration;
+ return (
+ currentTime >= chapterStart && currentTime < chapterEnd
+ );
+ });
+ return currentChapter ? `• ${currentChapter.title}` : "";
+ })()}
+ </div>
+ )}
</div>
</div>
<div className="flex justify-end space-x-1 sm:space-x-2">
diff --git a/apps/web/app/s/[videoId]/_components/Sidebar.tsx b/apps/web/app/s/[videoId]/_components/Sidebar.tsx
index 59337bc5f..7fc49003d 100644
--- a/apps/web/app/s/[videoId]/_components/Sidebar.tsx
+++ b/apps/web/app/s/[videoId]/_components/Sidebar.tsx
@@ -88,9 +88,14 @@ export const Sidebar: React.FC<SidebarProps> = ({
const [activeTab, setActiveTab] = useState<TabType>("activity");
const [[page, direction], setPage] = useState([0, 0]);
+ const hasExistingAiData =
+ aiData?.summary || (aiData?.chapters && aiData.chapters.length > 0);
+
const tabs = [
{ id: "activity", label: "Comments" },
- ...(aiUiEnabled ? [{ id: "summary", label: "Summary" }] : []),
+ ...(aiUiEnabled || hasExistingAiData
+ ? [{ id: "summary", label: "Summary" }]
+ : []),
{ id: "transcript", label: "Transcript" },
];
diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
index 5a1fcf018..ae8b69755 100644
--- a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx
@@ -214,11 +214,11 @@ const Comment: React.FC<{
<Avatar name={comment.authorName} />
<div className="flex-1">
<div className="flex items-center space-x-2">
- <span className="font-medium text-gray-900">
+ <span className="font-medium text-gray-12">
{comment.authorName || "Anonymous"}
</span>
<span
- className="text-sm text-gray-1"
+ className="text-sm text-gray-8"
data-tooltip-id={`comment-${comment.id}-timestamp`}
data-tooltip-content={formatTimestamp(commentDate)}
>
diff --git a/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx b/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx
index 0a10554a1..a48d5ef9c 100644
--- a/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx
+++ b/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx
@@ -109,7 +109,10 @@ export const Summary: React.FC<SummaryProps> = ({
hasProAccess,
});
- if (aiUiEnabled && !hasProAccess) {
+ const hasExistingAiData =
+ aiData?.summary || (aiData?.chapters && aiData.chapters.length > 0);
+
+ if (aiUiEnabled && !hasProAccess && !hasExistingAiData) {
return (
<div className="flex flex-col justify-center items-center p-8 h-full text-center">
<div className="space-y-4 max-w-sm">
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index d35f6f346..7057cbde4 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -14,13 +14,15 @@ import { getCurrentUser, userSelectProps } from "@cap/database/auth/session";
import type { Metadata, ResolvingMetadata } from "next";
import { notFound } from "next/navigation";
import { ImageViewer } from "./_components/ImageViewer";
-import { buildEnv, serverEnv } from "@cap/env";
+import { buildEnv } from "@cap/env";
import { getVideoAnalytics } from "@/actions/videos/get-analytics";
import { transcribeVideo } from "@/actions/videos/transcribe";
import { getScreenshot } from "@/actions/screenshots/get-screenshot";
-import { headers } from "next/headers";
+import { cookies, headers } from "next/headers";
import { generateAiMetadata } from "@/actions/videos/generate-ai-metadata";
import { isAiGenerationEnabled, isAiUiEnabled } from "@/utils/flags";
+import { PasswordOverlay } from "./_components/PasswordOverlay";
+import { decrypt } from "@cap/database/crypto";
export const dynamic = "auto";
export const dynamicParams = true;
@@ -41,6 +43,8 @@ type VideoWithOrganization = typeof videos.$inferSelect & {
organizationMembers?: string[];
organizationId?: string;
sharedOrganizations?: { id: string; name: string }[];
+ password?: string | null;
+ hasPassword?: boolean;
};
export async function generateMetadata(
@@ -149,6 +153,37 @@ export async function generateMetadata(
};
}
+ if (video.password !== null) {
+ return {
+ title: "Cap: Password Protected Video",
+ description: "This video is password protected.",
+ openGraph: {
+ images: [
+ {
+ url: new URL(
+ `/api/video/og?videoId=${videoId}`,
+ buildEnv.NEXT_PUBLIC_WEB_URL
+ ).toString(),
+ width: 1200,
+ height: 630,
+ },
+ ],
+ },
+ twitter: {
+ card: "summary_large_image",
+ title: "Cap: Password Protected Video",
+ description: "This video is password protected.",
+ images: [
+ new URL(
+ `/api/video/og?videoId=${videoId}`,
+ buildEnv.NEXT_PUBLIC_WEB_URL
+ ).toString(),
+ ],
+ },
+ robots: "noindex, nofollow",
+ };
+ }
+
return {
title: video.name + " | Cap Recording",
description: "Watch this video on Cap",
@@ -219,6 +254,7 @@ export default async function ShareVideoPage(props: Props) {
isScreenshot: videos.isScreenshot,
skipProcessing: videos.skipProcessing,
transcriptionStatus: videos.transcriptionStatus,
+ password: videos.password,
source: videos.source,
sharedOrganization: {
organizationId: sharedVideos.organizationId,
@@ -275,7 +311,6 @@ export default async function ShareVideoPage(props: Props) {
console.log("[ShareVideoPage] Starting transcription for video:", videoId);
await transcribeVideo(videoId, video.ownerId);
- // Re-fetch video data to get updated transcription status
const updatedVideoQuery = await db()
.select({
id: videos.id,
@@ -316,7 +351,7 @@ export default async function ShareVideoPage(props: Props) {
}
const currentMetadata = (video.metadata as VideoMetadata) || {};
- const metadata = currentMetadata; // Keep existing reference for compatibility
+ const metadata = currentMetadata;
let initialAiData = null;
let aiGenerationEnabled = false;
@@ -528,9 +563,10 @@ export default async function ShareVideoPage(props: Props) {
organizationMembers: membersList.map((member) => member.userId),
organizationId: video.sharedOrganization?.organizationId ?? undefined,
sharedOrganizations: sharedOrganizationsData,
+ password: null,
+ hasPassword: video.password !== null,
};
- // Check if AI UI should be shown for the current viewer
let aiUiEnabled = false;
if (user?.email) {
aiUiEnabled = isAiUiEnabled({
@@ -542,18 +578,39 @@ export default async function ShareVideoPage(props: Props) {
);
}
+ const authorized =
+ !videoWithOrganizationInfo.hasPassword ||
+ user?.id === videoWithOrganizationInfo.ownerId ||
+ (await verifyPasswordCookie(video.password ?? ""));
+
return (
- <Share
- data={videoWithOrganizationInfo}
- user={user}
- comments={commentsQuery}
- initialAnalytics={initialAnalytics}
- customDomain={customDomain}
- domainVerified={domainVerified}
- userOrganizations={userOrganizations}
- initialAiData={initialAiData}
- aiGenerationEnabled={aiGenerationEnabled}
- aiUiEnabled={aiUiEnabled}
- />
+ <div className="min-h-screen flex flex-col bg-[#F7F8FA]">
+ <PasswordOverlay
+ isOpen={!authorized}
+ videoId={videoWithOrganizationInfo.id}
+ />
+ {authorized && (
+ <Share
+ data={videoWithOrganizationInfo}
+ user={user}
+ comments={commentsQuery}
+ initialAnalytics={initialAnalytics}
+ customDomain={customDomain}
+ domainVerified={domainVerified}
+ userOrganizations={userOrganizations}
+ initialAiData={initialAiData}
+ aiGenerationEnabled={aiGenerationEnabled}
+ aiUiEnabled={aiUiEnabled}
+ />
+ )}
+ </div>
);
}
+
+async function verifyPasswordCookie(videoPassword: string) {
+ const password = cookies().get("x-cap-password")?.value;
+ if (!password) return false;
+
+ const decrypted = await decrypt(password).catch(() => "");
+ return decrypted === videoPassword;
+}
diff --git a/apps/web/components/UpgradeModal.tsx b/apps/web/components/UpgradeModal.tsx
index 9aa956fa4..e5a2c4d2f 100644
--- a/apps/web/components/UpgradeModal.tsx
+++ b/apps/web/components/UpgradeModal.tsx
@@ -87,6 +87,16 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
title: "Unlimited sharing",
description: "Cloud storage & shareable links",
},
+ {
+ icon: <Sparkles className={iconStyling} />,
+ title: "Cap AI",
+ description: "Automatic video chapters, summaries & more",
+ },
+ {
+ icon: <Lock className={iconStyling} />,
+ title: "Password protected videos",
+ description: "Enhanced security for your content",
+ },
{
icon: <Database className={iconStyling} />,
title: "Custom storage",
@@ -102,21 +112,11 @@ export const UpgradeModal = ({ open, onOpenChange }: UpgradeModalProps) => {
title: "Team features",
description: "Collaborate with your team and create shared spaces",
},
- {
- icon: <Sparkles className={iconStyling} />,
- title: "Cap AI (Coming Soon)",
- description: "Automatic video chapters, summaries & more",
- },
{
icon: <Infinity className={iconStyling} />,
title: "Unlimited views",
description: "No limits on video views",
},
- {
- icon: <Lock className={iconStyling} />,
- title: "Password protected videos",
- description: "Enhanced security for your content",
- },
{
icon: <BarChart3 className={iconStyling} />,
title: "Analytics",
diff --git a/apps/web/lib/safe-action.ts b/apps/web/lib/safe-action.ts
new file mode 100644
index 000000000..7f62198ae
--- /dev/null
+++ b/apps/web/lib/safe-action.ts
@@ -0,0 +1,3 @@
+import { createSafeActionClient } from "next-safe-action";
+
+export const actionClient = createSafeActionClient();
diff --git a/apps/web/package.json b/apps/web/package.json
index 836d508d6..324cb70e4 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -43,7 +43,7 @@
"@rive-app/react-canvas": "^4.18.7",
"@stripe/stripe-js": "^3.3.0",
"@t3-oss/env-nextjs": "^0.12.0",
- "@tanstack/react-query": "^5.51.11",
+ "@tanstack/react-query": "^5.75.4",
"@tanstack/react-store": "^0.5.5",
"@tanstack/store": "^0.5.5",
"@ts-rest/core": "^3.52.1",
@@ -92,7 +92,7 @@
"tailwind-merge": "^2.1.0",
"uuid": "^9.0.1",
"video.js": "^8.17.3",
- "zod": "^3.24.2"
+ "zod": "^3.24.4"
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
diff --git a/packages/database/crypto.ts b/packages/database/crypto.ts
index 96ab6cbcd..7ce0e1b79 100644
--- a/packages/database/crypto.ts
+++ b/packages/database/crypto.ts
@@ -1,4 +1,5 @@
import { serverEnv } from "@cap/env";
+import { timingSafeEqual } from "crypto";
const ALGORITHM = { name: "AES-GCM", length: 256 };
const IV_LENGTH = 12;
@@ -10,7 +11,6 @@ const ENCRYPTION_KEY = () => {
const key = serverEnv().DATABASE_ENCRYPTION_KEY;
if (!key) return;
- // Verify the encryption key is valid hex and correct length
try {
const keyBuffer = Buffer.from(key, "hex");
if (keyBuffer.length !== KEY_LENGTH) {
@@ -34,7 +34,6 @@ async function deriveKey(salt: Uint8Array): Promise<CryptoKey> {
const key = ENCRYPTION_KEY();
if (!key) throw new Error("Encryption key is not available");
- // Convert hex string to ArrayBuffer for Web Crypto API
const keyBuffer = Buffer.from(key, "hex");
const keyMaterial = await crypto.subtle.importKey(
@@ -79,7 +78,6 @@ export async function encrypt(text: string): Promise<string> {
encoded
);
- // Combine salt, IV, and encrypted content
const result = Buffer.concat([
Buffer.from(salt as any) as any,
Buffer.from(iv as any) as any,
@@ -103,12 +101,10 @@ export async function decrypt(encryptedText: string): Promise<string> {
try {
const encrypted = Buffer.from(encryptedText, "base64");
- // Extract the components
const salt = encrypted.subarray(0, SALT_LENGTH);
const iv = encrypted.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
const content = encrypted.subarray(SALT_LENGTH + IV_LENGTH);
- // Derive the same key using the extracted salt
const key = await deriveKey(salt as Uint8Array);
const decrypted = await crypto.subtle.decrypt(
@@ -128,3 +124,69 @@ export async function decrypt(encryptedText: string): Promise<string> {
throw new Error("Decryption failed");
}
}
+
+const PASSWORD_KEY_LENGTH = 32;
+const PASSWORD_ITERATIONS = 100000;
+const PASSWORD_HASH = "SHA-256";
+
+export async function hashPassword(password: string): Promise<string> {
+ if (!password) {
+ throw new Error("Cannot hash empty or null password");
+ }
+
+ const salt = crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
+ const keyMaterial = await crypto.subtle.importKey(
+ "raw",
+ new TextEncoder().encode(password),
+ "PBKDF2",
+ false,
+ ["deriveBits"]
+ );
+
+ const derived = await crypto.subtle.deriveBits(
+ {
+ name: "PBKDF2",
+ salt,
+ iterations: PASSWORD_ITERATIONS,
+ hash: PASSWORD_HASH,
+ },
+ keyMaterial,
+ PASSWORD_KEY_LENGTH * 8
+ );
+
+ const result = Buffer.concat([
+ Buffer.from(salt as any) as any,
+ Buffer.from(derived as any) as any,
+ ]);
+
+ return result.toString("base64");
+}
+
+export async function verifyPassword(stored: string, password: string): Promise<boolean> {
+ if (!stored || !password) return false;
+
+ const data = Buffer.from(stored, "base64");
+ const salt = data.subarray(0, SALT_LENGTH);
+ const hash = data.subarray(SALT_LENGTH);
+
+ const keyMaterial = await crypto.subtle.importKey(
+ "raw",
+ new TextEncoder().encode(password),
+ "PBKDF2",
+ false,
+ ["deriveBits"]
+ );
+
+ const derived = await crypto.subtle.deriveBits(
+ {
+ name: "PBKDF2",
+ salt,
+ iterations: PASSWORD_ITERATIONS,
+ hash: PASSWORD_HASH,
+ },
+ keyMaterial,
+ PASSWORD_KEY_LENGTH * 8
+ );
+
+ return timingSafeEqual(Buffer.from(hash), Buffer.from(derived));
+}
diff --git a/packages/database/migrations/0005_jazzy_brood.sql b/packages/database/migrations/0005_jazzy_brood.sql
new file mode 100644
index 000000000..28861e1e1
--- /dev/null
+++ b/packages/database/migrations/0005_jazzy_brood.sql
@@ -0,0 +1 @@
+ALTER TABLE `videos` ADD `password` text;
\ No newline at end of file
diff --git a/packages/database/migrations/0005_password_protection.sql b/packages/database/migrations/0005_password_protection.sql
new file mode 100644
index 000000000..ada292736
--- /dev/null
+++ b/packages/database/migrations/0005_password_protection.sql
@@ -0,0 +1 @@
+ALTER TABLE `videos` ADD `password` text;
diff --git a/packages/database/migrations/meta/0005_snapshot.json b/packages/database/migrations/meta/0005_snapshot.json
new file mode 100644
index 000000000..34a7b7d16
--- /dev/null
+++ b/packages/database/migrations/meta/0005_snapshot.json
@@ -0,0 +1,1339 @@
+{
+ "version": "5",
+ "dialect": "mysql",
+ "id": "db818ca1-e79f-4d6b-9c28-4d29eb8771ab",
+ "prevId": "08624504-7fe8-4741-bac1-0c308816f3d5",
+ "tables": {
+ "accounts": {
+ "name": "accounts",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "providerAccountId": {
+ "name": "providerAccountId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expires_in": {
+ "name": "expires_in",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token_expires_in": {
+ "name": "refresh_token_expires_in",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "token_type": {
+ "name": "token_type",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "tempColumn": {
+ "name": "tempColumn",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "user_id_idx": {
+ "name": "user_id_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ },
+ "provider_account_id_idx": {
+ "name": "provider_account_id_idx",
+ "columns": [
+ "providerAccountId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "accounts_id": {
+ "name": "accounts_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "accounts_id_unique": {
+ "name": "accounts_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "auth_api_keys": {
+ "name": "auth_api_keys",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(36)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "auth_api_keys_id": {
+ "name": "auth_api_keys_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "auth_api_keys_id_unique": {
+ "name": "auth_api_keys_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "comments": {
+ "name": "comments",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "varchar(6)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "timestamp": {
+ "name": "timestamp",
+ "type": "float",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "authorId": {
+ "name": "authorId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "videoId": {
+ "name": "videoId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "parentCommentId": {
+ "name": "parentCommentId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "video_id_idx": {
+ "name": "video_id_idx",
+ "columns": [
+ "videoId"
+ ],
+ "isUnique": false
+ },
+ "author_id_idx": {
+ "name": "author_id_idx",
+ "columns": [
+ "authorId"
+ ],
+ "isUnique": false
+ },
+ "parent_comment_id_idx": {
+ "name": "parent_comment_id_idx",
+ "columns": [
+ "parentCommentId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "comments_id": {
+ "name": "comments_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "comments_id_unique": {
+ "name": "comments_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "organization_invites": {
+ "name": "organization_invites",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organizationId": {
+ "name": "organizationId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "invitedEmail": {
+ "name": "invitedEmail",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "invitedByUserId": {
+ "name": "invitedByUserId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "expiresAt": {
+ "name": "expiresAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "organization_id_idx": {
+ "name": "organization_id_idx",
+ "columns": [
+ "organizationId"
+ ],
+ "isUnique": false
+ },
+ "invited_email_idx": {
+ "name": "invited_email_idx",
+ "columns": [
+ "invitedEmail"
+ ],
+ "isUnique": false
+ },
+ "invited_by_user_id_idx": {
+ "name": "invited_by_user_id_idx",
+ "columns": [
+ "invitedByUserId"
+ ],
+ "isUnique": false
+ },
+ "status_idx": {
+ "name": "status_idx",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "organization_invites_id": {
+ "name": "organization_invites_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "organization_invites_id_unique": {
+ "name": "organization_invites_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "organization_members": {
+ "name": "organization_members",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organizationId": {
+ "name": "organizationId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {
+ "user_id_idx": {
+ "name": "user_id_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ },
+ "organization_id_idx": {
+ "name": "organization_id_idx",
+ "columns": [
+ "organizationId"
+ ],
+ "isUnique": false
+ },
+ "user_id_organization_id_idx": {
+ "name": "user_id_organization_id_idx",
+ "columns": [
+ "userId",
+ "organizationId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "organization_members_id": {
+ "name": "organization_members_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "organization_members_id_unique": {
+ "name": "organization_members_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "organizations": {
+ "name": "organizations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ownerId": {
+ "name": "ownerId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "allowedEmailDomain": {
+ "name": "allowedEmailDomain",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "customDomain": {
+ "name": "customDomain",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "domainVerified": {
+ "name": "domainVerified",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "iconUrl": {
+ "name": "iconUrl",
+ "type": "varchar(1024)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "workosOrganizationId": {
+ "name": "workosOrganizationId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workosConnectionId": {
+ "name": "workosConnectionId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "owner_id_idx": {
+ "name": "owner_id_idx",
+ "columns": [
+ "ownerId"
+ ],
+ "isUnique": false
+ },
+ "custom_domain_idx": {
+ "name": "custom_domain_idx",
+ "columns": [
+ "customDomain"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "organizations_id": {
+ "name": "organizations_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "organizations_id_unique": {
+ "name": "organizations_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "s3_buckets": {
+ "name": "s3_buckets",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ownerId": {
+ "name": "ownerId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "region": {
+ "name": "region",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "endpoint": {
+ "name": "endpoint",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "bucketName": {
+ "name": "bucketName",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "accessKeyId": {
+ "name": "accessKeyId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "secretAccessKey": {
+ "name": "secretAccessKey",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "('aws')"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "s3_buckets_id": {
+ "name": "s3_buckets_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "s3_buckets_id_unique": {
+ "name": "s3_buckets_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "sessions": {
+ "name": "sessions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sessionToken": {
+ "name": "sessionToken",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires": {
+ "name": "expires",
+ "type": "datetime",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {
+ "session_token_idx": {
+ "name": "session_token_idx",
+ "columns": [
+ "sessionToken"
+ ],
+ "isUnique": true
+ },
+ "user_id_idx": {
+ "name": "user_id_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "sessions_id": {
+ "name": "sessions_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "sessions_id_unique": {
+ "name": "sessions_id_unique",
+ "columns": [
+ "id"
+ ]
+ },
+ "sessions_sessionToken_unique": {
+ "name": "sessions_sessionToken_unique",
+ "columns": [
+ "sessionToken"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "shared_videos": {
+ "name": "shared_videos",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "videoId": {
+ "name": "videoId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organizationId": {
+ "name": "organizationId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sharedByUserId": {
+ "name": "sharedByUserId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sharedAt": {
+ "name": "sharedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ }
+ },
+ "indexes": {
+ "video_id_idx": {
+ "name": "video_id_idx",
+ "columns": [
+ "videoId"
+ ],
+ "isUnique": false
+ },
+ "organization_id_idx": {
+ "name": "organization_id_idx",
+ "columns": [
+ "organizationId"
+ ],
+ "isUnique": false
+ },
+ "shared_by_user_id_idx": {
+ "name": "shared_by_user_id_idx",
+ "columns": [
+ "sharedByUserId"
+ ],
+ "isUnique": false
+ },
+ "video_id_organization_id_idx": {
+ "name": "video_id_organization_id_idx",
+ "columns": [
+ "videoId",
+ "organizationId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "shared_videos_id": {
+ "name": "shared_videos_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "shared_videos_id_unique": {
+ "name": "shared_videos_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "users": {
+ "name": "users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "lastName": {
+ "name": "lastName",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "emailVerified": {
+ "name": "emailVerified",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "image": {
+ "name": "image",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripeCustomerId": {
+ "name": "stripeCustomerId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripeSubscriptionId": {
+ "name": "stripeSubscriptionId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "thirdPartyStripeSubscriptionId": {
+ "name": "thirdPartyStripeSubscriptionId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripeSubscriptionStatus": {
+ "name": "stripeSubscriptionStatus",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "stripeSubscriptionPriceId": {
+ "name": "stripeSubscriptionPriceId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "activeOrganizationId": {
+ "name": "activeOrganizationId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "onboarding_completed_at": {
+ "name": "onboarding_completed_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "customBucket": {
+ "name": "customBucket",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "inviteQuota": {
+ "name": "inviteQuota",
+ "type": "int",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ }
+ },
+ "indexes": {
+ "email_idx": {
+ "name": "email_idx",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "users_id": {
+ "name": "users_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "users_id_unique": {
+ "name": "users_id_unique",
+ "columns": [
+ "id"
+ ]
+ },
+ "users_email_unique": {
+ "name": "users_email_unique",
+ "columns": [
+ "email"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "verification_tokens": {
+ "name": "verification_tokens",
+ "columns": {
+ "identifier": {
+ "name": "identifier",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires": {
+ "name": "expires",
+ "type": "datetime",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "verification_tokens_identifier": {
+ "name": "verification_tokens_identifier",
+ "columns": [
+ "identifier"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "verification_tokens_token_unique": {
+ "name": "verification_tokens_token_unique",
+ "columns": [
+ "token"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ },
+ "videos": {
+ "name": "videos",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ownerId": {
+ "name": "ownerId",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'My Video'"
+ },
+ "awsRegion": {
+ "name": "awsRegion",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "awsBucket": {
+ "name": "awsBucket",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "bucket": {
+ "name": "bucket",
+ "type": "varchar(15)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "public": {
+ "name": "public",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "videoStartTime": {
+ "name": "videoStartTime",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "audioStartTime": {
+ "name": "audioStartTime",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "xStreamInfo": {
+ "name": "xStreamInfo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "jobId": {
+ "name": "jobId",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "jobStatus": {
+ "name": "jobStatus",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "isScreenshot": {
+ "name": "isScreenshot",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "skipProcessing": {
+ "name": "skipProcessing",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "transcriptionStatus": {
+ "name": "transcriptionStatus",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(now())"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "onUpdate": true,
+ "default": "(now())"
+ },
+ "source": {
+ "name": "source",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "('{\"type\":\"MediaConvert\"}')"
+ }
+ },
+ "indexes": {
+ "id_idx": {
+ "name": "id_idx",
+ "columns": [
+ "id"
+ ],
+ "isUnique": false
+ },
+ "owner_id_idx": {
+ "name": "owner_id_idx",
+ "columns": [
+ "ownerId"
+ ],
+ "isUnique": false
+ },
+ "is_public_idx": {
+ "name": "is_public_idx",
+ "columns": [
+ "public"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "videos_id": {
+ "name": "videos_id",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "uniqueConstraints": {
+ "videos_id_unique": {
+ "name": "videos_id_unique",
+ "columns": [
+ "id"
+ ]
+ }
+ },
+ "checkConstraint": {}
+ }
+ },
+ "views": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "tables": {},
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.json
index db0803078..b443fa431 100644
--- a/packages/database/migrations/meta/_journal.json
+++ b/packages/database/migrations/meta/_journal.json
@@ -36,6 +36,13 @@
"when": 1747923172570,
"tag": "0004_good_microbe",
"breakpoints": true
+ },
+ {
+ "idx": 5,
+ "version": "5",
+ "when": 1748207569898,
+ "tag": "0005_jazzy_brood",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/packages/database/schema.ts b/packages/database/schema.ts
index 3d1f26acf..aea7e0527 100644
--- a/packages/database/schema.ts
+++ b/packages/database/schema.ts
@@ -202,6 +202,7 @@ export const videos = mysqlTable(
bucket: nanoIdNullable("bucket"),
metadata: json("metadata").$type<VideoMetadata>(),
public: boolean("public").notNull().default(true),
+ password: encryptedTextNullable("password"),
videoStartTime: varchar("videoStartTime", { length: 255 }),
audioStartTime: varchar("audioStartTime", { length: 255 }),
xStreamInfo: text("xStreamInfo"),