Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Check for custom domain in share page, around dash, etc
Richie McIlroy2317c6432e4b
diff --git a/apps/web/app/api/video/domain-info/route.ts b/apps/web/app/api/video/domain-info/route.tsnew file mode 100644index 000000000..f63649fa5--- /dev/null+++ b/apps/web/app/api/video/domain-info/route.ts@@ -0,0 +1,93 @@+import { db } from "@cap/database";+import { videos, sharedVideos, spaces } from "@cap/database/schema";+import { eq, and } from "drizzle-orm";+import { NextRequest } from "next/server";++export async function GET(request: NextRequest) {+ const { searchParams } = request.nextUrl;+ const videoId = searchParams.get("videoId");++ if (!videoId) {+ return Response.json({ error: "Video ID is required" }, { status: 400 });+ }++ try {+ // First, get the video to find the owner or shared space+ const video = await db+ .select({+ id: videos.id,+ ownerId: videos.ownerId,+ })+ .from(videos)+ .where(eq(videos.id, videoId))+ .limit(1);++ if (video.length === 0) {+ return Response.json({ error: "Video not found" }, { status: 404 });+ }++ const videoData = video[0];+ if (!videoData || !videoData.ownerId) {+ return Response.json({ error: "Invalid video data" }, { status: 500 });+ }++ // Check if the video is shared with a space+ const sharedVideo = await db+ .select({+ spaceId: sharedVideos.spaceId,+ })+ .from(sharedVideos)+ .where(eq(sharedVideos.videoId, videoId))+ .limit(1);++ let spaceId = null;+ if (sharedVideo.length > 0 && sharedVideo[0] && sharedVideo[0].spaceId) {+ spaceId = sharedVideo[0].spaceId;+ }++ // If we have a space ID, get the space's custom domain+ if (spaceId) {+ const space = await db+ .select({+ customDomain: spaces.customDomain,+ domainVerified: spaces.domainVerified,+ })+ .from(spaces)+ .where(eq(spaces.id, spaceId))+ .limit(1);++ if (space.length > 0 && space[0] && space[0].customDomain) {+ return Response.json({+ customDomain: space[0].customDomain,+ domainVerified: space[0].domainVerified || false,+ });+ }+ }++ // If no shared space or no custom domain, check the owner's space+ const ownerSpaces = await db+ .select({+ customDomain: spaces.customDomain,+ domainVerified: spaces.domainVerified,+ })+ .from(spaces)+ .where(eq(spaces.ownerId, videoData.ownerId))+ .limit(1);++ if (ownerSpaces.length > 0 && ownerSpaces[0] && ownerSpaces[0].customDomain) {+ return Response.json({+ customDomain: ownerSpaces[0].customDomain,+ domainVerified: ownerSpaces[0].domainVerified || false,+ });+ }++ // No custom domain found+ return Response.json({+ customDomain: null,+ domainVerified: false,+ });+ } catch (error) {+ console.error("Error fetching domain info:", error);+ return Response.json({ error: "Internal server error" }, { status: 500 });+ }+}\ No newline at end of filediff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsxindex 8465a8d2e..a38fb2a77 100644--- a/apps/web/app/s/[videoId]/Share.tsx+++ b/apps/web/app/s/[videoId]/Share.tsx@@ -38,6 +38,8 @@ interface ShareProps {comments: number;reactions: number;};+ customDomain: string | null;+ domainVerified: boolean;}export const Share: React.FC<ShareProps> = ({@@ -46,6 +48,8 @@ export const Share: React.FC<ShareProps> = ({comments,individualFiles,initialAnalytics,+ customDomain,+ domainVerified,}) => {const [analytics, setAnalytics] = useState(initialAnalytics);@@ -94,6 +98,8 @@ export const Share: React.FC<ShareProps> = ({data={data}user={user}individualFiles={individualFiles}+ customDomain={customDomain}+ domainVerified={domainVerified}/><div className="mt-4">diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsxindex 8157a3746..8ec5911a1 100644--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx@@ -14,6 +14,8 @@ export const ShareHeader = ({data,user,individualFiles,+ customDomain,+ domainVerified,}: {data: typeof videos.$inferSelect;user: typeof userSelectProps | null;@@ -21,6 +23,8 @@ export const ShareHeader = ({fileName: string;url: string;}[];+ customDomain: string | null;+ domainVerified: boolean;}) => {const { push, refresh } = useRouter();const [isEditing, setIsEditing] = useState(false);@@ -82,6 +86,22 @@ export const ShareHeader = ({}};+ const getVideoLink = () => {+ return customDomain && domainVerified+ ? `https://${customDomain}/s/${data.id}`+ : clientEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"+ ? `https://cap.link/${data.id}`+ : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${data.id}`;+ };++ const getDisplayLink = () => {+ return customDomain && domainVerified+ ? `${customDomain}/s/${data.id}`+ : clientEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"+ ? `cap.link/${data.id}`+ : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${data.id}`;+ };+return (<><div>@@ -144,24 +164,11 @@ export const ShareHeader = ({variant="gray"className="hover:bg-gray-300"onClick={() => {- if (- clientEnv.NEXT_PUBLIC_IS_CAP &&- NODE_ENV === "production"- ) {- navigator.clipboard.writeText(- `https://cap.link/${data.id}`- );- } else {- navigator.clipboard.writeText(- `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${data.id}`- );- }+ navigator.clipboard.writeText(getVideoLink());toast.success("Link copied to clipboard!");}}>- {clientEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"- ? `cap.link/${data.id}`- : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${data.id}`}+ {getDisplayLink()}<Copy className="ml-2 h-4 w-4" /></Button>{user !== null && (diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex 445b2669a..d79dd01d3 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -252,48 +252,82 @@ export default async function ShareVideoPage(props: Props) {);}- let individualFiles: {- fileName: string;- url: string;- }[] = [];+ console.log("[ShareVideoPage] Fetching individual files for video:", videoId);+ const individualFiles = await fetch(+ `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/video/individual-files?videoId=${videoId}`,+ {+ method: "GET",+ credentials: "include",+ cache: "no-store",+ }+ ).then((res) => res.json());++ console.log("[ShareVideoPage] Fetching analytics for video:", videoId);+ const analyticsResponse = await fetch(+ `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/video/analytics?videoId=${videoId}`,+ {+ method: "GET",+ credentials: "include",+ cache: "no-store",+ }+ );- if (video?.source.type === "desktopMP4") {- console.log(- "[ShareVideoPage] Fetching individual files for desktop MP4 video:",- videoId- );- const res = await fetch(- `${clientEnv.NEXT_PUBLIC_WEB_URL}/api/video/individual?videoId=${videoId}&userId=${video.ownerId}`,- {- method: "GET",- credentials: "include",- cache: "no-store",- }- );+ const analyticsData = await analyticsResponse.json();+ const initialAnalytics = {+ views: analyticsData.count || 0,+ comments: commentsQuery.filter((c) => c.type === "text").length,+ reactions: commentsQuery.filter((c) => c.type === "emoji").length,+ };- const data = await res.json();- individualFiles = data.files;- }+ // Fetch custom domain information+ let customDomain: string | null = null;+ let domainVerified = false;- console.log("[ShareVideoPage] Rendering Share component for video:", videoId);+ // Check if the video is shared with a space+ if (video.sharedSpace?.spaceId) {+ const spaceData = await db+ .select({+ customDomain: spaces.customDomain,+ domainVerified: spaces.domainVerified,+ })+ .from(spaces)+ .where(eq(spaces.id, video.sharedSpace.spaceId))+ .limit(1);- const analyticsData = await db- .select({- id: videos.id,- totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,- totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,- })- .from(videos)- .leftJoin(comments, eq(videos.id, comments.videoId))- .where(eq(videos.id, videoId))- .groupBy(videos.id);+ 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+ }+ }+ }- const initialAnalytics = {- views: 0,- comments: analyticsData[0]?.totalComments || 0,- reactions: analyticsData[0]?.totalReactions || 0,- };+ // If no custom domain from shared space, check the owner's space+ if (!customDomain && video.ownerId) {+ const ownerSpaces = await db+ .select({+ customDomain: spaces.customDomain,+ domainVerified: spaces.domainVerified,+ })+ .from(spaces)+ .where(eq(spaces.ownerId, video.ownerId))+ .limit(1);++ if (+ ownerSpaces.length > 0 &&+ ownerSpaces[0] &&+ 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+ }+ }+ }+ // Get space members if the video is shared with a spaceconst membersList = video.sharedSpace?.spaceId? await db.select({@@ -316,6 +350,8 @@ export default async function ShareVideoPage(props: Props) {comments={commentsQuery}individualFiles={individualFiles}initialAnalytics={initialAnalytics}+ customDomain={customDomain}+ domainVerified={domainVerified}/>);}