Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add share iframe redirect URL helper

Richie McIlroycf9b57bed796
diff --git a/apps/web/lib/share-iframe-navigation.ts b/apps/web/lib/share-iframe-navigation.ts
new file mode 100644
index 000000000..e7fce4d19
--- /dev/null
+++ b/apps/web/lib/share-iframe-navigation.ts
@@ -0,0 +1,22 @@
+const SHARE_VIDEO_PATH_PATTERN = /^\/s\/([^/]+)\/?$/;
+
+export function getShareIframeRedirectUrl({
+ method,
+ requestUrl,
+ fetchDestination,
+}: {
+ method: string;
+ requestUrl: string;
+ fetchDestination: string | null;
+}) {
+ if (method !== "GET" || fetchDestination?.toLowerCase() !== "iframe") {
+ return null;
+ }
+
+ const url = new URL(requestUrl);
+ const videoId = url.pathname.match(SHARE_VIDEO_PATH_PATTERN)?.[1];
+ if (!videoId) return null;
+
+ url.pathname = `/embed/${videoId}`;
+ return url;
+}