Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add connect domain button + remove individualFiles

Richie McIlroyb2a0ca9b2401
diff --git a/apps/web/app/api/video/individual/route.ts b/apps/web/app/api/video/individual/route.ts
deleted file mode 100644
index 5092a545b..000000000
--- a/apps/web/app/api/video/individual/route.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-import { type NextRequest } from "next/server";
-import { db } from "@cap/database";
-import { s3Buckets, videos } from "@cap/database/schema";
-import { eq } from "drizzle-orm";
-import { ListObjectsV2Command } from "@aws-sdk/client-s3";
-import { getCurrentUser } from "@cap/database/auth/session";
-import { getHeaders } from "@/utils/helpers";
-import { createS3Client, getS3Bucket } from "@/utils/s3";
-import { S3_BUCKET_URL } from "@cap/utils";
-
-export const revalidate = 3599;
-
-export async function OPTIONS(request: NextRequest) {
- const origin = request.headers.get("origin") as string;
-
- return new Response(null, {
- status: 200,
- headers: getHeaders(origin),
- });
-}
-
-export async function GET(request: NextRequest) {
- const searchParams = request.nextUrl.searchParams;
- const userId = searchParams.get("userId") || "";
- const videoId = searchParams.get("videoId") || "";
- const origin = request.headers.get("origin") as string;
-
- if (!userId || !videoId) {
- return new Response(
- JSON.stringify({
- error: true,
- message: "userId or videoId not supplied",
- }),
- { status: 401, headers: getHeaders(origin) }
- );
- }
-
- const query = await db
- .select({ video: videos, bucket: s3Buckets })
- .from(videos)
- .leftJoin(s3Buckets, eq(videos.bucket, s3Buckets.id))
- .where(eq(videos.id, videoId));
-
- if (query.length === 0) {
- return new Response(
- JSON.stringify({ error: true, message: "Video does not exist" }),
- { status: 401, headers: getHeaders(origin) }
- );
- }
-
- const result = query[0];
- if (!result) {
- return new Response(
- JSON.stringify({ error: true, message: "Video does not exist" }),
- { status: 401, headers: getHeaders(origin) }
- );
- }
-
- const { video, bucket } = result;
-
- if (video.public === false) {
- const user = await getCurrentUser();
-
- if (!user || user.id !== video.ownerId) {
- return new Response(
- JSON.stringify({ error: true, message: "Video is not public" }),
- { status: 401, headers: getHeaders(origin) }
- );
- }
- }
-
- const Bucket = await getS3Bucket(bucket);
- const individualPrefix = `${userId}/${videoId}/individual/`;
-
- try {
- const [s3Client] = await createS3Client(bucket);
-
- const objectsCommand = new ListObjectsV2Command({
- Bucket,
- Prefix: individualPrefix,
- });
-
- const objects = await s3Client.send(objectsCommand);
-
- if (!objects.Contents || objects.Contents.length === 0) {
- return new Response(
- JSON.stringify({ error: true, message: "No individual files found" }),
- { status: 404, headers: getHeaders(origin) }
- );
- }
-
- const individualFiles = objects.Contents.map((object) => {
- const key = object.Key as string;
- const fileName = key.split("/").pop();
- return {
- fileName,
- url: `${S3_BUCKET_URL}/${key}`,
- };
- });
-
- return new Response(JSON.stringify({ files: individualFiles }), {
- status: 200,
- headers: getHeaders(origin),
- });
- } catch (error) {
- console.error("Error listing individual files", error);
- return new Response(
- JSON.stringify({
- error: true,
- message: "Error listing individual files",
- }),
- { status: 500, headers: getHeaders(origin) }
- );
- }
-}
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index 1970186d1..e528091c4 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -30,10 +30,6 @@ interface ShareProps {
data: VideoWithSpaceInfo;
user: typeof userSelectProps | null;
comments: CommentWithAuthor[];
- individualFiles: {
- fileName: string;
- url: string;
- }[];
initialAnalytics: {
views: number;
comments: number;
@@ -47,13 +43,11 @@ export const Share: React.FC<ShareProps> = ({
data,
user,
comments,
- individualFiles,
initialAnalytics,
customDomain,
domainVerified,
}) => {
const [analytics, setAnalytics] = useState(initialAnalytics);
- // Use custom date from metadata if it exists, similar to CapCard.tsx
const effectiveDate = data.metadata?.customCreatedAt
? new Date(data.metadata.customCreatedAt)
: data.createdAt;
@@ -83,7 +77,6 @@ export const Share: React.FC<ShareProps> = ({
fetchViewCount();
}, [data.id]);
- // Update analytics when comments change
useEffect(() => {
setAnalytics((prev) => ({
...prev,
@@ -98,7 +91,6 @@ export const Share: React.FC<ShareProps> = ({
<ShareHeader
data={{ ...data, createdAt: effectiveDate }}
user={user}
- individualFiles={individualFiles}
customDomain={customDomain}
domainVerified={domainVerified}
/>
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index ae92c43e8..fd0b752c4 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -1,29 +1,24 @@
-import { Button, LogoBadge } from "@cap/ui";
+import { Button } from "@cap/ui";
import { videos } from "@cap/database/schema";
import moment from "moment";
import { userSelectProps } from "@cap/database/auth/session";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "react-hot-toast";
-import { Copy, Loader2 } from "lucide-react";
-import JSZip from "jszip";
-import { saveAs } from "file-saver";
+import { Copy, Globe2 } from "lucide-react";
import { clientEnv, NODE_ENV } from "@cap/env";
import { editTitle } from "@/actions/videos/edit-title";
+import { isUserOnProPlan } from "@cap/utils";
+import { UpgradeModal } from "@/components/UpgradeModal";
export const ShareHeader = ({
data,
user,
- individualFiles,
customDomain,
domainVerified,
}: {
data: typeof videos.$inferSelect;
user: typeof userSelectProps | null;
- individualFiles?: {
- fileName: string;
- url: string;
- }[];
customDomain: string | null;
domainVerified: boolean;
}) => {
@@ -31,6 +26,7 @@ export const ShareHeader = ({
const [isEditing, setIsEditing] = useState(false);
const [title, setTitle] = useState(data.name);
const [isDownloading, setIsDownloading] = useState(false);
+ const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
const handleBlur = async () => {
setIsEditing(false);
@@ -54,29 +50,6 @@ export const ShareHeader = ({
}
};
- const downloadZip = async () => {
- if (!individualFiles) return;
-
- setIsDownloading(true);
- const zip = new JSZip();
-
- try {
- for (const file of individualFiles) {
- const response = await fetch(file.url);
- const blob = await response.blob();
- zip.file(file.fileName, blob);
- }
-
- const content = await zip.generateAsync({ type: "blob" });
- saveAs(content, `${data.id}.zip`);
- } catch (error) {
- console.error("Error downloading zip:", error);
- toast.error("Failed to download files. Please try again.");
- } finally {
- setIsDownloading(false);
- }
- };
-
const getVideoLink = () => {
return customDomain && domainVerified
? `https://${customDomain}/s/${data.id}`
@@ -93,6 +66,12 @@ export const ShareHeader = ({
: `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${data.id}`;
};
+ const isUserPro = user
+ ? isUserOnProPlan({
+ subscriptionStatus: user.stripeSubscriptionStatus,
+ })
+ : false;
+
return (
<>
<div>
@@ -130,38 +109,29 @@ export const ShareHeader = ({
</p>
</div>
</div>
- {(user !== null ||
- (individualFiles && individualFiles.length > 0)) && (
- <div className="flex items-center space-x-2">
- {individualFiles && individualFiles.length > 0 && (
- <div>
- <Button
- variant="gray"
- onClick={downloadZip}
- disabled={isDownloading}
+ {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 h-4 w-4" />
+ </Button>
+ {user !== null && !isUserPro && (
+ <button
+ className="cursor-pointer flex items-center text-sm text-gray-400 hover:text-blue-500 mt-1"
+ onClick={() => setUpgradeModalOpen(true)}
>
- {isDownloading ? (
- <>
- <Loader2 className="mr-2 h-4 w-4 animate-spin" />
- Downloading...
- </>
- ) : (
- "Download Assets"
- )}
- </Button>
- </div>
- )}
- <Button
- variant="gray"
- className="hover:bg-gray-300"
- onClick={() => {
- navigator.clipboard.writeText(getVideoLink());
- toast.success("Link copied to clipboard!");
- }}
- >
- {getDisplayLink()}
- <Copy className="ml-2 h-4 w-4" />
- </Button>
+ <Globe2 className="w-4 h-4 mr-1" />
+ Connect a custom domain
+ </button>
+ )}
+ </div>
{user !== null && (
<div className="hidden md:flex">
<Button
@@ -169,7 +139,10 @@ export const ShareHeader = ({
push(`${clientEnv.NEXT_PUBLIC_WEB_URL}/dashboard`);
}}
>
- Go to Dashboard
+ <span className="hidden lg:block text-white text-sm">
+ Go to
+ </span>{" "}
+ Dashboard
</Button>
</div>
)}
@@ -177,6 +150,10 @@ export const ShareHeader = ({
)}
</div>
</div>
+ <UpgradeModal
+ open={upgradeModalOpen}
+ onOpenChange={setUpgradeModalOpen}
+ />
</>
);
};
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index e8337c361..864236544 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -237,11 +237,9 @@ export default async function ShareVideoPage(props: Props) {
reactions: commentsQuery.filter((c) => c.type === "emoji").length,
};
- // Fetch custom domain information
let customDomain: string | null = null;
let domainVerified = false;
- // Check if the video is shared with a space
if (video.sharedSpace?.spaceId) {
const spaceData = await db
.select({
@@ -254,14 +252,12 @@ export default async function ShareVideoPage(props: Props) {
if (spaceData.length > 0 && spaceData[0] && spaceData[0].customDomain) {
customDomain = spaceData[0].customDomain;
- // Handle domainVerified which could be a Date or boolean
if (spaceData[0].domainVerified !== null) {
- domainVerified = true; // If it exists (not null), consider it verified
+ domainVerified = true;
}
}
}
- // If no custom domain from shared space, check the owner's space
if (!customDomain && video.ownerId) {
const ownerSpaces = await db
.select({
@@ -278,14 +274,12 @@ export default async function ShareVideoPage(props: Props) {
ownerSpaces[0].customDomain
) {
customDomain = ownerSpaces[0].customDomain;
- // Handle domainVerified which could be a Date or boolean
if (ownerSpaces[0].domainVerified !== null) {
- domainVerified = true; // If it exists (not null), consider it verified
+ domainVerified = true;
}
}
}
- // Get space members if the video is shared with a space
const membersList = video.sharedSpace?.spaceId
? await db
.select({
@@ -306,7 +300,6 @@ export default async function ShareVideoPage(props: Props) {
data={videoWithSpaceInfo}
user={user}
comments={commentsQuery}
- individualFiles={[]}
initialAnalytics={initialAnalytics}
customDomain={customDomain}
domainVerified={domainVerified}