Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

improvement: Share links (#716)

Ameer Al Ashhabd8441ea592c1
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx
index 48cf98494..6c10d7f69 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx
@@ -1,5 +1,6 @@
import { Tooltip } from "@/components/Tooltip";
-import { buildEnv } from "@cap/env";
+import { usePublicEnv } from "@/utils/public-env";
+import { buildEnv, NODE_ENV } from "@cap/env";
import { Button } from "@cap/ui";
import { faDownload, faLink } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -67,14 +68,21 @@ const buttons = (
tooltipContent: "Copy link",
onClick: (e: React.MouseEvent) => {
e.stopPropagation();
+
+ const { webUrl } = usePublicEnv();
+
const getVideoLink = () => {
- if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {
- return `https://${customDomain}/s/${capId}`;
+ if (NODE_ENV === "development" && customDomain && domainVerified) {
+ return `${customDomain}/s/${capId}`;
+ } else if (NODE_ENV === "development" && !customDomain && !domainVerified) {
+ return `${webUrl}/s/${capId}`;
+ } else if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {
+ return `${customDomain}/s/${capId}`;
} else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {
- return `https://cap.link/${capId}`;
+ return `cap.link/${capId}`;
} else {
- return `${location.origin}/s/${capId}`;
+ return `${webUrl}/s/${capId}`;
}
};
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index 164d34664..9c50451d7 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -26,6 +26,7 @@ export const ShareHeader = ({
domainVerified,
sharedOrganizations = [],
sharedSpaces = [],
+ NODE_ENV,
}: {
data: typeof videos.$inferSelect;
user: typeof userSelectProps | null;
@@ -45,6 +46,7 @@ export const ShareHeader = ({
iconUrl?: string;
organizationId: string;
}[];
+ NODE_ENV: "production" | "development" | "test";
}) => {
const { push, refresh } = useRouter();
const [isEditing, setIsEditing] = useState(false);
@@ -87,17 +89,11 @@ export const ShareHeader = ({
};
const getVideoLink = () => {
- if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {
- return `https://${customDomain}/s/${data.id}`;
- } else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {
- return `https://cap.link/${data.id}`;
- } else {
+ if (NODE_ENV === "development" && customDomain && domainVerified) {
+ return `${customDomain}/s/${data.id}`;
+ } else if (NODE_ENV === "development" && !customDomain && !domainVerified) {
return `${webUrl}/s/${data.id}`;
- }
- };
-
- const getDisplayLink = () => {
- if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {
+ } else if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {
return `${customDomain}/s/${data.id}`;
} else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {
return `cap.link/${data.id}`;
@@ -210,7 +206,7 @@ export const ShareHeader = ({
toast.success("Link copied to clipboard!");
}}
>
- {getDisplayLink()}
+ {getVideoLink()}
<Copy className="ml-2 w-4 h-4" />
</Button>
</div>
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index a5faddf13..706f1ab93 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -412,54 +412,34 @@ async function AuthorizedContent({
}
const customDomainPromise = (async () => {
- let customDomain: string | null = null;
- let domainVerified = false;
-
- if (video.sharedOrganization?.organizationId) {
- const organizationData = await db()
- .select({
- customDomain: organizations.customDomain,
- domainVerified: organizations.domainVerified,
- })
- .from(organizations)
- .where(eq(organizations.id, video.sharedOrganization.organizationId))
- .limit(1);
-
- if (
- organizationData.length > 0 &&
- organizationData[0] &&
- organizationData[0].customDomain
- ) {
- customDomain = organizationData[0].customDomain;
- if (organizationData[0].domainVerified !== null) {
- domainVerified = true;
- }
- }
+ if (!user) {
+ return { customDomain: null, domainVerified: false };
+ }
+ const activeOrganizationId = user.activeOrganizationId;
+ if (!activeOrganizationId) {
+ return { customDomain: null, domainVerified: false };
}
- if (!customDomain && video.ownerId) {
- const ownerOrganizations = await db()
- .select({
- customDomain: organizations.customDomain,
- domainVerified: organizations.domainVerified,
- })
- .from(organizations)
- .where(eq(organizations.ownerId, video.ownerId))
- .limit(1);
+ // Fetch the active org
+ const orgArr = await db()
+ .select({
+ customDomain: organizations.customDomain,
+ domainVerified: organizations.domainVerified,
+ })
+ .from(organizations)
+ .where(eq(organizations.id, activeOrganizationId))
+ .limit(1);
- if (
- ownerOrganizations.length > 0 &&
- ownerOrganizations[0] &&
- ownerOrganizations[0].customDomain
- ) {
- customDomain = ownerOrganizations[0].customDomain;
- if (ownerOrganizations[0].domainVerified !== null) {
- domainVerified = true;
- }
- }
+ const org = orgArr[0];
+ if (
+ org &&
+ org.customDomain &&
+ org.domainVerified !== null &&
+ user.id === video.ownerId
+ ) {
+ return { customDomain: org.customDomain, domainVerified: true };
}
-
- return { customDomain, domainVerified };
+ return { customDomain: null, domainVerified: false };
})();
const sharedOrganizationsPromise = db()
@@ -566,6 +546,7 @@ async function AuthorizedContent({
videoWithOrganizationInfo.sharedOrganizations || []
}
userOrganizations={userOrganizations}
+ NODE_ENV={process.env.NODE_ENV}
/>
<Share