Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Add preview GIF and update Drive UI/callback
Richie McIlroy1c82180dff12
diff --git a/apps/web/app/(org)/dashboard/settings/organization/integrations/storage-integrations.tsx b/apps/web/app/(org)/dashboard/settings/organization/integrations/storage-integrations.tsxindex 4cbb3d5d9..298634177 100644--- a/apps/web/app/(org)/dashboard/settings/organization/integrations/storage-integrations.tsx+++ b/apps/web/app/(org)/dashboard/settings/organization/integrations/storage-integrations.tsx@@ -6,9 +6,7 @@ import {ChevronRightIcon,DatabaseIcon,FolderOpenIcon,- HardDriveIcon,InfoIcon,- UserIcon,VideoIcon,} from "lucide-react";import { useRouter } from "next/navigation";@@ -199,16 +197,6 @@ export function OrganizationStorageIntegrations({provider === "s3" ? "S3 enabled" : "Google Drive enabled",);- const setDriveRootLocation = () =>- runMutation(- () =>- setOrganizationGoogleDriveLocation({- organizationId,- folderId: "root",- }),- "Google Drive location updated",- );-const loadFolderBrowser = async (parent: { id: string; name: string },history: Array<{ id: string; name: string }>,@@ -295,6 +283,12 @@ export function OrganizationStorageIntegrations({const hasDriveLocation = !!settings.googleDrive?.folderId;const selectedDriveName = settings.googleDrive?.driveName ?? "My Drive";const selectedFolderName = settings.googleDrive?.folderName ?? null;+ const driveIsActive =+ bothConfigured && settings.activeProvider === "googleDrive";+ const folderBreadcrumb = selectedFolderName+ ? `${selectedDriveName} › ${selectedFolderName}`+ : selectedDriveName;+ const filePathPreview = `${selectedFolderName ?? selectedDriveName} / user-id / video-id`;return (<div className="flex flex-col gap-4">@@ -570,76 +564,46 @@ export function OrganizationStorageIntegrations({<div className="border-t border-gray-3 px-3.5 py-4">{settings.googleDrive?.connected ? (<div className="flex flex-col gap-3">- {(settings.googleDrive.email ||- settings.googleDrive.folderName) && (- <div className="flex items-center gap-4 text-[12px]">- {settings.googleDrive.email && (- <span className="text-gray-10">- {settings.googleDrive.email}- </span>- )}- {settings.googleDrive.folderName && (- <span className="text-gray-12 font-medium">- {settings.googleDrive.folderName}- </span>- )}- </div>+ {settings.googleDrive.email && (+ <p className="text-[12px] text-gray-10">+ Connected as{" "}+ <span className="text-gray-12 font-medium">+ {settings.googleDrive.email}+ </span>+ </p>)}- <div className="flex flex-col gap-2.5 rounded-lg border border-gray-3 bg-gray-2 p-3">+ <div className="flex flex-col gap-3 rounded-lg border border-gray-3 bg-gray-2 p-3"><div className="flex items-center justify-between"><p className="text-[12px] font-medium text-gray-12">Storage destination</p>- {settings.activeProvider === "googleDrive" ? (+ {driveIsActive ? (<span className="inline-flex items-center gap-1 px-2 py-0.5 text-[11px] font-medium rounded-md bg-green-500/10 text-green-600"><span className="size-1.5 rounded-full bg-green-500" />Enabled</span>) : (<span className="text-[11px] text-gray-9">- Not enabled+ {hasDriveLocation+ ? bothConfigured+ ? "Not enabled"+ : "Ready to enable"+ : "Choose a folder to enable"}</span>)}</div>- <div className="grid gap-1.5 sm:grid-cols-3">- <div className="flex items-center gap-2 rounded-md bg-gray-3 px-2.5 py-2 min-w-0">- <HardDriveIcon className="size-3.5 shrink-0 text-gray-9" />- <div className="min-w-0">- <p className="text-[10px] text-gray-9">Drive</p>- <p className="truncate text-[11px] font-medium text-gray-12">- {selectedDriveName}- </p>- </div>- </div>- <div className="flex items-center gap-2 rounded-md bg-gray-3 px-2.5 py-2 min-w-0">- <FolderOpenIcon className="size-3.5 shrink-0 text-gray-9" />- <div className="min-w-0">- <p className="text-[10px] text-gray-9">Folder</p>- <p className="truncate text-[11px] font-medium text-gray-12">- {selectedFolderName ?? "Select a folder"}- </p>- </div>++ <div className="flex items-center gap-3 rounded-md bg-gray-3 px-3 py-2.5">+ <div className="flex items-center justify-center size-8 rounded-md bg-gray-1 shrink-0">+ <FolderOpenIcon className="size-4 text-gray-10" /></div>- <div className="flex items-center gap-2 rounded-md bg-gray-3 px-2.5 py-2 min-w-0">- <UserIcon className="size-3.5 shrink-0 text-gray-9" />- <div className="min-w-0">- <p className="text-[10px] text-gray-9">Member</p>- <p className="truncate text-[11px] font-medium text-gray-12">- User ID- </p>- </div>+ <div className="min-w-0 flex-1">+ <p className="text-[10px] text-gray-9">Folder</p>+ <p className="truncate text-[12px] font-medium text-gray-12">+ {folderBreadcrumb}+ </p></div>- </div>- <div className="flex items-center gap-2 rounded-md bg-gray-3 px-2.5 py-1.5 text-[11px] text-gray-10">- <VideoIcon className="size-3.5 shrink-0 text-gray-9" />- <span className="min-w-0 truncate">- {hasDriveLocation- ? `${selectedFolderName ?? selectedDriveName} / user-id / video-id`- : "Select a folder before enabling"}- </span>- </div>- <div className="flex items-center gap-2 pt-1"><Buttontype="button"size="xs"@@ -647,34 +611,42 @@ export function OrganizationStorageIntegrations({onClick={openFolderBrowser}disabled={isPending || folderBrowserLoading}>- <FolderOpenIcon className="size-3" />- Select Folder- </Button>- <Button- type="button"- size="xs"- variant="gray"- onClick={setDriveRootLocation}- disabled={isPending}- >- Use Root- </Button>- <Button- type="button"- size="xs"- onClick={() => setActiveProvider("googleDrive")}- disabled={!hasDriveLocation || isPending}- >- Enable+ Change</Button></div>++ {hasDriveLocation && (+ <div className="flex items-center gap-2 rounded-md bg-gray-3 px-3 py-2 text-[11px] text-gray-10">+ <VideoIcon className="size-3.5 shrink-0 text-gray-9" />+ <span className="text-gray-9">Recordings saved as</span>+ <span className="min-w-0 truncate text-gray-12 font-medium">+ {filePathPreview}+ </span>+ </div>+ )}++ {!driveIsActive && (+ <div className="flex justify-end pt-0.5">+ <Button+ type="button"+ size="xs"+ onClick={() => setActiveProvider("googleDrive")}+ disabled={!hasDriveLocation || isPending}+ >+ Enable+ </Button>+ </div>+ )}</div>{folderBrowserOpen && (<div className="flex flex-col gap-2 rounded-lg border border-gray-3 p-3">- <div className="flex items-center justify-between">+ <div className="flex items-center justify-between gap-2"><div className="min-w-0">- <p className="text-[12px] font-medium text-gray-12">+ <p className="text-[10px] text-gray-9">+ Browsing Google Drive+ </p>+ <p className="truncate text-[12px] font-medium text-gray-12">{folderBrowserParent.name}</p></div>@@ -697,7 +669,7 @@ export function OrganizationStorageIntegrations({onClick={selectCurrentDriveFolder}disabled={folderBrowserLoading || isPending}>- Use This Folder+ Use this folder</Button></div></div>@@ -772,9 +744,10 @@ export function OrganizationStorageIntegrations({</div></div>) : (- <div className="flex items-center justify-between">+ <div className="flex items-center justify-between gap-3"><p className="text-[12px] text-gray-10">- Link your Google account to store uploads in Drive.+ Link your Google account to store uploads in a "Cap" folder in+ your Drive. You can change the location after connecting.</p><Buttontype="button"diff --git a/apps/web/app/api/desktop/[...route]/storage.ts b/apps/web/app/api/desktop/[...route]/storage.tsindex 4d5ae5cce..7644ebae9 100644--- a/apps/web/app/api/desktop/[...route]/storage.ts+++ b/apps/web/app/api/desktop/[...route]/storage.ts@@ -20,6 +20,7 @@ import { Organisation, Storage, User } from "@cap/web-domain";import { zValidator } from "@hono/zod-validator";import { and, desc, eq, isNull } from "drizzle-orm";import { Hono } from "hono";+import { revalidatePath } from "next/cache";import { z } from "zod";import { getCachedGoogleDriveStorageQuota } from "@/lib/google-drive-storage-quota";import { runPromise } from "@/lib/server";@@ -117,26 +118,61 @@ const escapeHtml = (value: string) =>.replace(/"/g, """).replace(/'/g, "'");-const htmlResponse = (title: string, body: string) => `<!doctype html>+const googleDriveIconSvg = `<svg viewBox="0 0 87.3 78" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8h-27.5c0 1.55.4 3.1 1.2 4.5z" fill="#0066da"/><path d="m43.65 25-13.75-23.8c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0 -1.2 4.5h27.5z" fill="#00ac47"/><path d="m73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5h-27.502l5.852 11.5z" fill="#ea4335"/><path d="m43.65 25 13.75-23.8c-1.35-.8-2.9-1.2-4.5-1.2h-18.5c-1.6 0-3.15.45-4.5 1.2z" fill="#00832d"/><path d="m59.8 53h-32.3l-13.75 23.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z" fill="#2684fc"/><path d="m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3l-13.75 23.8 16.15 28h27.45c0-1.55-.4-3.1-1.2-4.5z" fill="#ffba00"/></svg>`;++const baseHtmlStyles = `body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;min-height:100vh;display:grid;place-items:center;background:#f6f5f3;color:#1f1f1f}+main{max-width:440px;padding:40px 32px;text-align:center}+.icon{width:56px;height:56px;margin:0 auto 20px;display:block}+h1{font-size:22px;margin:0 0 8px;font-weight:600;letter-spacing:-0.01em}+p{font-size:14px;line-height:1.55;color:#5f5f5f;margin:0 auto;max-width:340px}+.countdown{font-weight:500;color:#1f1f1f;font-variant-numeric:tabular-nums}+.actions{margin-top:24px;display:flex;justify-content:center}+.button{display:inline-flex;align-items:center;gap:8px;padding:10px 18px;border-radius:9999px;background:#1f1f1f;color:#ffffff;text-decoration:none;font-size:13px;font-weight:500;transition:background-color .15s ease;border:none;cursor:pointer;font-family:inherit}+.button:hover{background:#383838}`;++type CallbackHtmlOptions = {+ title: string;+ body: string;+ redirectUrl?: string;+ redirectLabel?: string;+ redirectSeconds?: number;+};++const htmlResponse = ({+ title,+ body,+ redirectUrl,+ redirectLabel,+ redirectSeconds = 5,+}: CallbackHtmlOptions) => {+ const message = redirectUrl+ ? `${escapeHtml(body)} Redirecting in <span class="countdown" id="cap-countdown">${redirectSeconds}</span>s.`+ : escapeHtml(body);+ const action = redirectUrl+ ? `<div class="actions"><a class="button" href="${escapeHtml(redirectUrl)}">${escapeHtml(redirectLabel ?? "Back to Cap")}</a></div>`+ : "";+ const script = redirectUrl+ ? `<script>(function(){var s=${redirectSeconds};var el=document.getElementById('cap-countdown');var t=setInterval(function(){s-=1;if(s<=0){clearInterval(t);window.location.replace(${JSON.stringify(redirectUrl)});return;}if(el)el.textContent=String(s);},1000);})();</script>`+ : "";+ return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(title)}</title>-<style>-body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;min-height:100vh;display:grid;place-items:center;background:#f6f5f3;color:#1f1f1f}-main{max-width:480px;padding:32px;text-align:center}-h1{font-size:24px;margin:0 0 12px}-p{font-size:15px;line-height:1.5;color:#555;margin:0}-</style>+<style>${baseHtmlStyles}</style></head><body><main>+<div class="icon">${googleDriveIconSvg}</div><h1>${escapeHtml(title)}</h1>-<p>${escapeHtml(body)}</p>+<p>${message}</p>+${action}</main>+${script}</body></html>`;+};const getGoogleDriveIntegration = (ownerId: User.UserId) =>db()@@ -373,14 +409,16 @@ protectedApp.delete("/google-drive/disconnect", async (c) => {app.route("/", protectedApp);app.get("/google-drive/callback", async (c) => {+ const orgRedirectUrl = "/dashboard/settings/organization/integrations";+ let organizationIdForRedirect: Organisation.OrganisationId | undefined;try {const error = c.req.query("error");if (error) {return c.html(- htmlResponse(- "Google Drive was not connected",- "You can close this window and try again from Cap settings.",- ),+ htmlResponse({+ title: "Google Drive was not connected",+ body: "You can close this window and try again from Cap settings.",+ }),400,);}@@ -389,15 +427,16 @@ app.get("/google-drive/callback", async (c) => {const state = c.req.query("state");if (!code || !state) {return c.html(- htmlResponse(- "Google Drive was not connected",- "The authorization response was missing required data.",- ),+ htmlResponse({+ title: "Google Drive was not connected",+ body: "The authorization response was missing required data.",+ }),400,);}const { userId, organizationId } = verifyGoogleDriveState(state);+ organizationIdForRedirect = organizationId;if (organizationId) {const organization = await requireOrganizationOwner(userId,@@ -415,15 +454,15 @@ app.get("/google-drive/callback", async (c) => {scope: tokens.scope,folderLayout: organizationId ? "userVideo" : "video",};- const config: GoogleDriveIntegrationConfig = organizationId- ? initialConfig- : {- ...initialConfig,- folderId: await ensureGoogleDriveFolder(initialConfig, "Cap").pipe(- runPromise,- ),- folderName: "Cap",- };+ const defaultFolderId = await ensureGoogleDriveFolder(+ initialConfig,+ "Cap",+ ).pipe(runPromise);+ const config: GoogleDriveIntegrationConfig = {+ ...initialConfig,+ folderId: defaultFolderId,+ folderName: "Cap",+ };const email = await getGoogleDriveUserEmail(config).pipe(runPromise);const encryptedConfig = await encrypt(JSON.stringify({ ...config, email: email ?? undefined }),@@ -508,18 +547,43 @@ app.get("/google-drive/callback", async (c) => {});});+ if (organizationId) {+ revalidatePath(orgRedirectUrl);+ revalidatePath("/dashboard/settings/organization");+ }+return c.html(htmlResponse(- "Google Drive connected",- "Return to Cap settings to manage your storage provider.",+ organizationId+ ? {+ title: "Google Drive connected",+ body: 'Your Google account is now linked to Cap. We\'ve created a "Cap" folder in your Drive to store your recordings.',+ redirectUrl: orgRedirectUrl,+ redirectLabel: "Back to settings",+ redirectSeconds: 5,+ }+ : {+ title: "Google Drive connected",+ body: "Return to the Cap app to finish setting up your storage.",+ },),);} catch (error) {console.error("Google Drive OAuth callback failed:", error);return c.html(htmlResponse(- "Google Drive was not connected",- "You can close this window and try again from Cap settings.",+ organizationIdForRedirect+ ? {+ title: "Google Drive was not connected",+ body: "Something went wrong while linking your Google account. You can try again from Cap settings.",+ redirectUrl: orgRedirectUrl,+ redirectLabel: "Back to settings",+ redirectSeconds: 8,+ }+ : {+ title: "Google Drive was not connected",+ body: "You can close this window and try again from Cap settings.",+ },),500,);diff --git a/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsxindex 7d0ca9d58..970f237aa 100644--- a/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx+++ b/apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx@@ -31,6 +31,7 @@ import {resolvePlaybackSource,shouldFallbackToRawPlaybackSource,} from "./playback-source";+import { VideoPreviewGif } from "./VideoPreviewGif";import {MediaPlayer,MediaPlayerCaptions,@@ -645,6 +646,16 @@ export function CapVideoPlayer({</TooltipContent></Tooltip>)}+ <VideoPreviewGif+ videoId={videoId}+ visible={+ videoLoaded &&+ !hasPlayedOnce &&+ !showUploadFailureOverlay &&+ !showPlaybackResolutionError &&+ Boolean(resolvedSrc.data)+ }+ />{resolvedSrc.data && (<MediaPlayerVideosrc={iosLevelPatchedUrl ?? resolvedSrc.data.url}diff --git a/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsxindex f73ff9df2..e9085b88a 100644--- a/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx+++ b/apps/web/app/s/[videoId]/_components/HLSVideoPlayer.tsx@@ -21,6 +21,7 @@ import {shouldReloadPlaybackAfterUploadCompletes,useUploadProgress,} from "./ProgressCircle";+import { VideoPreviewGif } from "./VideoPreviewGif";import {MediaPlayer,MediaPlayerCaptions,@@ -709,6 +710,16 @@ export function HLSVideoPlayer({</motion.div>)}</AnimatePresence>+ <VideoPreviewGif+ videoId={videoId}+ visible={+ videoLoaded &&+ !hasPlayedOnce &&+ !hasFailedOrError &&+ !hlsInitFailed &&+ !isLiveSegments+ }+ /><MediaPlayerVideosrc={undefined} // HLS source is handled by HLS.jsref={videoRef}diff --git a/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx b/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsxnew file mode 100644index 000000000..9b8c94963--- /dev/null+++ b/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx@@ -0,0 +1,49 @@+"use client";++import type { Video } from "@cap/web-domain";+import clsx from "clsx";+import Image from "next/image";+import { useState } from "react";++interface VideoPreviewGifProps {+ videoId: Video.VideoId;+ visible: boolean;+ className?: string;+}++function getPreviewGifSrc(videoId: Video.VideoId) {+ return `/api/video/preview?videoId=${encodeURIComponent(videoId)}&fallback=none`;+}++export function VideoPreviewGif({+ videoId,+ visible,+ className,+}: VideoPreviewGifProps) {+ const [status, setStatus] = useState<"loading" | "loaded" | "error">(+ "loading",+ );++ if (!visible || status === "error") return null;++ return (+ <Image+ key={videoId}+ src={getPreviewGifSrc(videoId)}+ alt=""+ aria-hidden="true"+ unoptimized+ fill+ sizes="(max-width: 768px) 100vw, 75vw"+ priority+ draggable={false}+ className={clsx(+ "object-contain absolute inset-0 z-[5] w-full h-full pointer-events-none transition-opacity duration-200",+ status === "loaded" ? "opacity-100" : "opacity-0",+ className,+ )}+ onLoad={() => setStatus("loaded")}+ onError={() => setStatus("error")}+ />+ );+}diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex 7212e0f04..ef451fa83 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -180,10 +180,6 @@ export async function generateMetadata(`/api/video/preview?videoId=${videoId}&fallback=og`,buildEnv.NEXT_PUBLIC_WEB_URL,).toString();- const ogImageUrl = new URL(- `/api/video/og?videoId=${videoId}`,- buildEnv.NEXT_PUBLIC_WEB_URL,- ).toString();const playlistUrl = new URL(`/api/playlist?videoId=${video.id}`,buildEnv.NEXT_PUBLIC_WEB_URL,@@ -193,19 +189,7 @@ export async function generateMetadata(title: `${video.name} | Cap Recording`,description: "Watch this video on Cap",openGraph: {- images: [- {- url: previewImageUrl,- width: 480,- height: 270,- type: "image/gif",- },- {- url: ogImageUrl,- width: 1200,- height: 630,- },- ],+ images: [{ url: previewImageUrl }],videos: [{url: playlistUrl,