Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add rich HTML video link clipboard copy

Richie McIlroy0d88ce6bbd9e
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
index b3e59e439..3b433b091 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -47,6 +47,10 @@ import {
} from "@/components/VideoThumbnail";
import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";
import { ThumbnailRequest } from "@/lib/Requests/ThumbnailRequest";
+import {
+ copyRichVideoLink,
+ videoPreviewImageUrl,
+} from "@/lib/video-share-clipboard";
import { usePublicEnv } from "@/utils/public-env";
import { PasswordDialog } from "../PasswordDialog";
@@ -314,7 +318,11 @@ export const CapCard = ({
};
const handleCopy = (text: string) => {
- navigator.clipboard.writeText(text);
+ copyRichVideoLink({
+ url: text,
+ title: cap.name || "Cap Recording",
+ previewImageUrl: videoPreviewImageUrl(webUrl, cap.id),
+ });
setCopyPressed(true);
setTimeout(() => {
setCopyPressed(false);
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index fee6a73c4..69dd78504 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -28,6 +28,10 @@ import type { Spaces } from "@/app/(org)/dashboard/dashboard-data";
import { useCurrentUser } from "@/app/Layout/AuthContext";
import { SignedImageUrl } from "@/components/SignedImageUrl";
import { UpgradeModal } from "@/components/UpgradeModal";
+import {
+ copyRichVideoLink,
+ videoPreviewImageUrl,
+} from "@/lib/video-share-clipboard";
import { usePublicEnv } from "@/utils/public-env";
import { navigateWithTransition } from "@/utils/view-transition";
import type { SharePageBranding, VideoData } from "../types";
@@ -244,6 +248,13 @@ export const ShareHeader = ({
return `${m}:${String(s).padStart(2, "0")}`;
};
+ const copyShareLink = (url: string) =>
+ copyRichVideoLink({
+ url,
+ title: displayTitle || "Cap Recording",
+ previewImageUrl: videoPreviewImageUrl(webUrl, data.id),
+ });
+
const handleCopyClick = () => {
const video = document.querySelector("video");
const currentTime = video ? Math.floor(video.currentTime) : 0;
@@ -252,7 +263,7 @@ export const ShareHeader = ({
setCapturedTime(currentTime);
setShowCopyOptions(true);
} else {
- navigator.clipboard.writeText(getVideoLink());
+ copyShareLink(getVideoLink());
setLinkCopied(true);
setTimeout(() => setLinkCopied(false), 2000);
}
@@ -262,7 +273,7 @@ export const ShareHeader = ({
const link = withTimestamp
? `${getVideoLink()}?t=${capturedTime}`
: getVideoLink();
- navigator.clipboard.writeText(link);
+ copyShareLink(link);
setShowCopyOptions(false);
setLinkCopied(true);
setTimeout(() => setLinkCopied(false), 2000);
diff --git a/apps/web/lib/video-share-clipboard.ts b/apps/web/lib/video-share-clipboard.ts
new file mode 100644
index 000000000..a7685abdf
--- /dev/null
+++ b/apps/web/lib/video-share-clipboard.ts
@@ -0,0 +1,72 @@
+// Rich "Copy link" for Cap videos — writes text/html alongside the plain URL
+// so pasting into Gmail/Outlook produces a branded, clickable thumbnail (the
+// way Loom share links behave), while Slack/plain fields still get the URL.
+
+const escapeHtml = (value: string) =>
+ value
+ .replace(/&/g, "&")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;")
+ .replace(/"/g, "&quot;");
+
+export type RichVideoLink = {
+ /** The share URL to copy (may include ?t= timestamp). */
+ url: string;
+ title: string;
+ /**
+ * Absolute, publicly fetchable image URL (email proxies fetch it without
+ * cookies). The animated preview GIF with the OG card as fallback.
+ */
+ previewImageUrl: string;
+};
+
+export const videoPreviewImageUrl = (webUrl: string, videoId: string) =>
+ `${webUrl}/api/video/preview?videoId=${videoId}&fallback=og`;
+
+export const richVideoLinkHtml = ({
+ url,
+ title,
+ previewImageUrl,
+}: RichVideoLink) => {
+ const safeUrl = escapeHtml(url);
+ const safeTitle = escapeHtml(title);
+ const safeImage = escapeHtml(previewImageUrl);
+ // Keep the markup minimal and inline-styled — email clients strip most
+ // other things. The image links to the video, with a text link below.
+ return (
+ `<div>` +
+ `<a href="${safeUrl}" title="${safeTitle}">` +
+ `<img src="${safeImage}" alt="${safeTitle}" width="420" style="display:block;width:420px;max-width:100%;border-radius:10px;" />` +
+ `</a>` +
+ `<p style="margin:8px 0 0 0;">` +
+ `<a href="${safeUrl}">${safeTitle}</a> — Watch on Cap` +
+ `</p>` +
+ `</div>`
+ );
+};
+
+/**
+ * Copies the link with a rich HTML representation when the browser allows it,
+ * falling back to plain text. Must be called from a user gesture.
+ */
+export const copyRichVideoLink = async (link: RichVideoLink) => {
+ try {
+ if (
+ typeof ClipboardItem !== "undefined" &&
+ typeof navigator.clipboard?.write === "function"
+ ) {
+ await navigator.clipboard.write([
+ new ClipboardItem({
+ "text/plain": new Blob([link.url], { type: "text/plain" }),
+ "text/html": new Blob([richVideoLinkHtml(link)], {
+ type: "text/html",
+ }),
+ }),
+ ]);
+ return;
+ }
+ } catch {
+ // Rich copy denied or unsupported — fall through to plain text.
+ }
+ await navigator.clipboard.writeText(link.url);
+};