From 624bb7737ad65ad5a48a95b95bab963825cb4eef Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:47:18 +0000 Subject: [PATCH 01/13] feat(web): brand colour setting for share pages and embeds --- apps/web/__tests__/unit/player-brand.test.ts | 146 ++++++++ .../organization/shareable-link-icon.ts | 30 +- .../components/OrganizationDetailsCard.tsx | 2 + .../components/ShareableLinkBrandColor.tsx | 316 ++++++++++++++++++ apps/web/app/globals.css | 25 ++ .../call-to-action/CallToActionDialog.tsx | 29 +- .../_components/video/media-player.tsx | 4 +- apps/web/lib/player-brand.ts | 152 +++++++++ 8 files changed, 692 insertions(+), 12 deletions(-) create mode 100644 apps/web/__tests__/unit/player-brand.test.ts create mode 100644 apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx create mode 100644 apps/web/lib/player-brand.ts diff --git a/apps/web/__tests__/unit/player-brand.test.ts b/apps/web/__tests__/unit/player-brand.test.ts new file mode 100644 index 00000000000..9e911a85755 --- /dev/null +++ b/apps/web/__tests__/unit/player-brand.test.ts @@ -0,0 +1,146 @@ +import { describe, expect, it } from "vitest"; +import { + contrastRatio, + getPlayerBrand, + MIN_CONTROL_CONTRAST, + PLAYER_BRAND_INK, + PLAYER_BRAND_WHITE, + playerBrandAttributes, + playerColorFromOrganizationMetadata, + resolvePlayerBrand, +} from "@/lib/player-brand"; + +describe("contrastRatio", () => { + it("matches the WCAG reference values", () => { + expect(contrastRatio("#000000", "#FFFFFF")).toBeCloseTo(21, 5); + expect(contrastRatio("#FFFFFF", "#FFFFFF")).toBeCloseTo(1, 5); + expect(contrastRatio("#767676", "#FFFFFF")).toBeCloseTo(4.54, 2); + }); +}); + +describe("resolvePlayerBrand", () => { + it("rejects anything that is not a hex colour", () => { + for (const value of [null, undefined, "", "blue", "#12", "#GGGGGG", 42]) { + expect(resolvePlayerBrand(value)).toBeNull(); + } + }); + + it("normalises shorthand and lowercase hex", () => { + expect(resolvePlayerBrand("#f60")?.color).toBe("#FF6600"); + expect(resolvePlayerBrand("1f6feb")?.color).toBe("#1F6FEB"); + }); + + it("picks whichever text colour reads better on the button", () => { + for (const color of [ + "#1F6FEB", + "#000000", + "#FFFFFF", + "#FFD60A", + "#7A4DFF", + "#12A150", + "#808080", + ]) { + const brand = resolvePlayerBrand(color); + if (!brand) throw new Error("expected a brand"); + const chosen = contrastRatio(color, brand.foreground); + const other = contrastRatio( + color, + brand.foreground === PLAYER_BRAND_WHITE + ? PLAYER_BRAND_INK + : PLAYER_BRAND_WHITE, + ); + expect(chosen).toBeGreaterThanOrEqual(other); + expect(chosen).toBeGreaterThanOrEqual(4.5); + } + expect(resolvePlayerBrand("#0B1F3A")?.foreground).toBe(PLAYER_BRAND_WHITE); + expect(resolvePlayerBrand("#FFD60A")?.foreground).toBe(PLAYER_BRAND_INK); + }); + + it("keeps the progress bar white when the colour vanishes on dark video", () => { + const navy = resolvePlayerBrand("#0B1F3A"); + expect(navy?.accent).toBeNull(); + expect(contrastRatio("#0B1F3A", "#000000")).toBeLessThan( + MIN_CONTROL_CONTRAST, + ); + + const orange = resolvePlayerBrand("#F26B1D"); + expect(orange?.accent).toBe("#F26B1D"); + }); + + it("darkens light-text buttons and lightens dark-text buttons on hover", () => { + expect(resolvePlayerBrand("#1F6FEB")?.hover).not.toBe("#1F6FEB"); + const blue = resolvePlayerBrand("#1F6FEB"); + const yellow = resolvePlayerBrand("#FFD60A"); + if (!blue || !yellow) throw new Error("expected brands"); + expect(contrastRatio(blue.hover, "#000000")).toBeLessThan( + contrastRatio(blue.color, "#000000"), + ); + expect(contrastRatio(yellow.hover, "#000000")).toBeGreaterThan( + contrastRatio(yellow.color, "#000000"), + ); + }); +}); + +describe("playerColorFromOrganizationMetadata", () => { + it("reads only branding.playerColor", () => { + expect( + playerColorFromOrganizationMetadata({ + branding: { playerColor: "#12a150" }, + }), + ).toBe("#12A150"); + expect( + playerColorFromOrganizationMetadata({ + branding: { colors: { primary: "#12A150" } }, + }), + ).toBeNull(); + for (const metadata of [null, undefined, "x", [], { branding: null }]) { + expect(playerColorFromOrganizationMetadata(metadata)).toBeNull(); + } + expect( + playerColorFromOrganizationMetadata({ + branding: { playerColor: "red; background: url(x)" }, + }), + ).toBeNull(); + }); +}); + +describe("getPlayerBrand", () => { + const metadata = { branding: { playerColor: "#7A4DFF" } }; + + it("applies the colour only for Pro owners", () => { + expect( + getPlayerBrand({ ownerIsPro: true, organizationMetadata: metadata }) + ?.color, + ).toBe("#7A4DFF"); + expect( + getPlayerBrand({ ownerIsPro: false, organizationMetadata: metadata }), + ).toBeNull(); + }); +}); + +describe("playerBrandAttributes", () => { + it("renders nothing without a brand", () => { + expect(playerBrandAttributes(null)).toEqual({}); + }); + + it("exposes the colour as CSS variables", () => { + const attributes = playerBrandAttributes(resolvePlayerBrand("#F26B1D")); + expect(attributes["data-player-brand"]).toBe(""); + expect(attributes["data-player-brand-accent"]).toBe(""); + expect(attributes.style).toMatchObject({ + "--player-brand": "#F26B1D", + "--player-brand-foreground": PLAYER_BRAND_INK, + "--player-brand-accent": "#F26B1D", + }); + expect( + (attributes.style as Record)["--player-brand-ring"], + ).toMatch(/^\d+(\.\d+)? \d+(\.\d+)?% \d+(\.\d+)?%$/); + }); + + it("leaves the accent off for dark colours", () => { + const attributes = playerBrandAttributes(resolvePlayerBrand("#0B1F3A")); + expect(attributes["data-player-brand"]).toBe(""); + expect(attributes["data-player-brand-accent"]).toBeUndefined(); + expect(attributes.style).not.toHaveProperty("--player-brand-accent"); + }); +}); diff --git a/apps/web/actions/organization/shareable-link-icon.ts b/apps/web/actions/organization/shareable-link-icon.ts index f4642f3cb73..02f13152a82 100644 --- a/apps/web/actions/organization/shareable-link-icon.ts +++ b/apps/web/actions/organization/shareable-link-icon.ts @@ -6,11 +6,12 @@ import { organizations, users } from "@cap/database/schema"; import { userIsPro } from "@cap/utils"; import { ImageUploads } from "@cap/web-backend"; import { Organisation } from "@cap/web-domain"; -import { eq } from "drizzle-orm"; +import { eq, sql } from "drizzle-orm"; import { Effect, Option } from "effect"; import { revalidatePath } from "next/cache"; import { organizationSettingsKeepingLinkOverride } from "@/lib/organization-settings-write"; import { runPromise } from "@/lib/server"; +import { normalizeHexColor } from "@/lib/share-call-to-action"; import { requireOrganizationSettingsManager } from "./authorization"; const allowedImageTypes = new Set(["image/jpeg", "image/png"]); @@ -202,3 +203,30 @@ export async function selectShareableLinkBrandingOrganization( return { success: true }; } + +export async function updateShareableLinkBrandColor({ + organizationId, + color, +}: { + organizationId: Organisation.OrganisationId; + color: string | null; +}) { + const playerColor = color === null ? null : normalizeHexColor(color); + if (color !== null && !playerColor) { + throw new Error("Enter a hex colour like #1F6FEB"); + } + + const organization = await getManageableProOrganization(organizationId); + const patch = JSON.stringify({ branding: { playerColor } }); + + await db() + .update(organizations) + .set({ + metadata: sql`JSON_MERGE_PATCH(COALESCE(${organizations.metadata}, JSON_OBJECT()), CAST(${patch} AS JSON))`, + }) + .where(eq(organizations.id, organization.id)); + + revalidateOrganizationBrandingPaths(); + + return { success: true, color: playerColor }; +} diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/OrganizationDetailsCard.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/OrganizationDetailsCard.tsx index 06dab6659f1..21475d91fd0 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/OrganizationDetailsCard.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/OrganizationDetailsCard.tsx @@ -6,6 +6,7 @@ import AccessEmailDomain from "./AccessEmailDomain"; import { CustomDomain } from "./CustomDomain"; import { OrganizationIcon } from "./OrganizationIcon"; import OrgName from "./OrgName"; +import { ShareableLinkBrandColor } from "./ShareableLinkBrandColor"; import { ShareableLinkIcon } from "./ShareableLinkIcon"; export const OrganizationDetailsCard = () => { @@ -25,6 +26,7 @@ export const OrganizationDetailsCard = () => { + diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx new file mode 100644 index 00000000000..9c354b6f695 --- /dev/null +++ b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx @@ -0,0 +1,316 @@ +"use client"; + +import { faPlay } from "@fortawesome/free-solid-svg-icons/faPlay"; +import { useMutation } from "@tanstack/react-query"; +import clsx from "clsx"; +import { Check, Pipette } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { useEffect, useId, useMemo, useState } from "react"; +import { toast } from "sonner"; +import { updateShareableLinkBrandColor } from "@/actions/organization/shareable-link-icon"; +import { FontAwesomeIcon } from "@/components/FontAwesomeIcon"; +import { UpgradeModal } from "@/components/UpgradeModal"; +import { + playerBrandAttributes, + playerColorFromOrganizationMetadata, + resolvePlayerBrand, +} from "@/lib/player-brand"; +import { normalizeHexColor } from "@/lib/share-call-to-action"; +import { useDashboardContext } from "../../../Contexts"; +import { ProChip, SettingsRow } from "../_components/settings-ui"; + +const CAP_PLAY_BLUE = "#3B82F6"; + +function brandPalette(metadata: unknown): string[] { + if (typeof metadata !== "object" || metadata === null) return []; + const branding = (metadata as { branding?: unknown }).branding; + if (typeof branding !== "object" || branding === null) return []; + const colors = (branding as { colors?: unknown }).colors; + if (typeof colors !== "object" || colors === null) return []; + const values = ["primary", "secondary", "accent", "background"] + .map((key) => normalizeHexColor((colors as Record)[key])) + .filter((value): value is string => value !== null); + return [...new Set(values)]; +} + +export const ShareableLinkBrandColor = () => { + const router = useRouter(); + const hexInputId = useId(); + const noteId = useId(); + const { activeOrganization, user } = useDashboardContext(); + const organization = activeOrganization?.organization; + const organizationId = organization?.id; + const savedColor = playerColorFromOrganizationMetadata( + organization?.metadata, + ); + const palette = useMemo( + () => brandPalette(organization?.metadata), + [organization?.metadata], + ); + + const [draft, setDraft] = useState(savedColor); + const [hexText, setHexText] = useState(savedColor ?? ""); + const [showUpgradeModal, setShowUpgradeModal] = useState(false); + + useEffect(() => { + setDraft(savedColor); + setHexText(savedColor ?? ""); + }, [savedColor]); + + const save = useMutation({ + mutationFn: (color: string | null) => { + if (!organizationId) throw new Error("No organization selected"); + return updateShareableLinkBrandColor({ organizationId, color }); + }, + onSuccess: (result) => { + toast.success( + result.color ? "Brand colour saved" : "Share pages use Cap blue again", + ); + router.refresh(); + }, + onError: (error) => { + toast.error( + error instanceof Error ? error.message : "Couldn't save brand colour", + ); + }, + }); + + const choose = (color: string | null) => { + if (!user.isPro) { + setShowUpgradeModal(true); + return; + } + setDraft(color); + setHexText(color ?? ""); + }; + + const hexValid = hexText === "" || normalizeHexColor(hexText) !== null; + const dirty = draft !== savedColor; + const brand = resolvePlayerBrand(draft); + const customSelected = + draft !== null && !palette.includes(draft) && draft !== CAP_PLAY_BLUE; + + return ( + <> + } + description="Colours the play button, progress bar and focus rings on your share pages and embeds." + > +
+
+
+ choose(null)} + /> + {palette.map((color) => ( + choose(color)} + /> + ))} + +
+ +
+ + { + if (!user.isPro) setShowUpgradeModal(true); + }} + onChange={(event) => { + const next = event.currentTarget.value.trim(); + setHexText(next); + if (next === "") { + setDraft(null); + return; + } + const parsed = normalizeHexColor(next); + if (parsed && user.isPro) setDraft(parsed); + }} + className={clsx( + "px-2.5 w-28 h-9 font-mono text-[13px] uppercase rounded-lg border outline-none bg-gray-1 text-gray-12 placeholder:text-gray-8 focus:ring-2 focus:ring-blue-9/30", + hexValid + ? "border-gray-4 focus:border-blue-8" + : "border-red-500 focus:border-red-500", + )} + /> +
+ +

+ {!hexValid + ? "Use a six digit hex colour, like #1F6FEB." + : brand && !brand.accent + ? "This colour is too dark to see on video, so the progress bar and focus rings stay white. The play button uses it." + : brand + ? `Play button text is ${brand.foreground === "#FFFFFF" ? "white" : "dark"} so it stays readable.` + : "Share pages and embeds use Cap blue."} +

+ + {dirty && ( +
+ + +
+ )} +
+ + +
+
+ + + ); +}; + +function Swatch({ + label, + color, + selected, + disabled, + onSelect, +}: { + label: string; + color: string; + selected: boolean; + disabled: boolean; + onSelect: () => void; +}) { + const foreground = resolvePlayerBrand(color)?.foreground; + return ( + + ); +} + +function PlayerPreview({ color }: { color: string | null }) { + const attributes = playerBrandAttributes(resolvePlayerBrand(color)); + return ( +
+
+
+ +
+
+
+
+
+
+
+
+
+
+ + 0:42 / 1:52 + +
+
+ ); +} diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css index 320de2429e8..7a576d47918 100644 --- a/apps/web/app/globals.css +++ b/apps/web/app/globals.css @@ -1195,3 +1195,28 @@ footer a { } } } + +/* Organization brand colour on share pages and embeds. Set by + `playerBrandAttributes` (lib/player-brand.ts); without the attribute these + rules match nothing and the player keeps Cap's own colours. */ +[data-player-brand] .player-brand-play { + background-color: var(--player-brand); + color: var(--player-brand-foreground); +} + +[data-player-brand] .player-brand-play:hover { + background-color: var(--player-brand-hover); +} + +[data-player-brand] .player-brand-play > svg { + color: var(--player-brand-foreground); +} + +[data-player-brand-accent] .player-brand-range, +[data-player-brand-accent] .player-brand-thumb { + background-color: var(--player-brand-accent); +} + +[data-player-brand-accent] [data-slot="media-player"] { + --ring: var(--player-brand-ring); +} diff --git a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx index fc891fdfb7f..71ae36b236f 100644 --- a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx +++ b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx @@ -52,8 +52,11 @@ const EMPTY_FORM: FormState = { const PREVIEW_PLACEHOLDER_LABEL = "Book a call"; -function formFromCallToAction(cta: ShareCallToAction | null): FormState { - if (!cta) return EMPTY_FORM; +function formFromCallToAction( + cta: ShareCallToAction | null, + brandColor: string | null, +): FormState { + if (!cta) return brandColor ? { ...EMPTY_FORM, color: brandColor } : EMPTY_FORM; return { label: cta.label, url: cta.url, @@ -97,6 +100,7 @@ export function CallToActionDialog({ callToAction, onSaved, onUpgradeRequest, + brandColor = null, }: { open: boolean; onOpenChange: (open: boolean) => void; @@ -104,9 +108,11 @@ export function CallToActionDialog({ callToAction: ShareCallToAction | null; onSaved?: (callToAction: ShareCallToAction | null) => void; onUpgradeRequest: () => void; + /** The organization's brand colour, offered first and used for new CTAs. */ + brandColor?: string | null; }) { const [form, setForm] = useState(() => - formFromCallToAction(callToAction), + formFromCallToAction(callToAction, brandColor), ); const [errors, setErrors] = useState({}); const [touched, setTouched] = useState>({}); @@ -127,12 +133,12 @@ export function CallToActionDialog({ const opening = open && !wasOpenRef.current; wasOpenRef.current = open; if (!opening) return; - setForm(formFromCallToAction(callToAction)); + setForm(formFromCallToAction(callToAction, brandColor)); setErrors({}); setTouched({}); setPreviewMode("end"); setPending(null); - }, [open, callToAction]); + }, [open, callToAction, brandColor]); const liveErrors = useMemo(() => { const result = validateCallToAction(form); @@ -410,6 +416,7 @@ export function CallToActionDialog({ update("color", color)} + brandColor={brandColor} />
@@ -696,18 +703,22 @@ function TextInput({ function ColorPicker({ value, onChange, + brandColor, }: { value: string; onChange: (color: string) => void; + brandColor: string | null; }) { const normalized = normalizeHexColor(value) ?? DEFAULT_CTA_COLOR; - const isCustom = !CTA_COLOR_PRESETS.some( - (preset) => preset.value === normalized, - ); + const presets = + brandColor && !CTA_COLOR_PRESETS.some((preset) => preset.value === brandColor) + ? [{ name: "Brand", value: brandColor }, ...CTA_COLOR_PRESETS] + : CTA_COLOR_PRESETS; + const isCustom = !presets.some((preset) => preset.value === normalized); return (
- {CTA_COLOR_PRESETS.map((preset) => { + {presets.map((preset) => { const selected = preset.value === normalized; return ( + + +
+
+ {( + [ + { id: "frame", label: "Pick a frame" }, + { id: "upload", label: "Upload image" }, + ] as const + ).map((tab) => ( + + ))} +
+ + {canPickFrame && ( +
+
+
+
+ + + seekTo(Number(event.currentTarget.value)) + } + className="h-1.5 flex-1 cursor-pointer appearance-none rounded-full bg-gray-4 accent-blue-9 disabled:cursor-not-allowed disabled:opacity-50" + /> + + {formatClockWithHundredths(frameTime)} + +
+
+ )} + {mode === "upload" && ( +
+ + {image && ( +

+ Click the image to choose another. +

+ )} + {imageError && ( +

+ {imageError} +

+ )} +
+ )} + {!canPickFrame && ( +

+ Frames can be picked once the video finishes processing. +

+ )} +
+ +
+ {hasCustomThumbnail && ( + + )} +
+ + +
+
+ + + ); +} + +export default CustomThumbnailDialog; diff --git a/apps/web/lib/custom-thumbnail.ts b/apps/web/lib/custom-thumbnail.ts new file mode 100644 index 00000000000..223f208a713 --- /dev/null +++ b/apps/web/lib/custom-thumbnail.ts @@ -0,0 +1,74 @@ +export const CUSTOM_THUMBNAIL_MAX_DIMENSION = 1920; + +/** + * Server actions accept 1 MB bodies. Images are re-encoded in the browser to + * a JPEG under this, which leaves room for the multipart envelope. + */ +export const CUSTOM_THUMBNAIL_MAX_BYTES = 900 * 1024; + +/** What people can pick before it is resized in the browser. */ +export const CUSTOM_THUMBNAIL_MAX_SOURCE_BYTES = 20 * 1024 * 1024; + +export const CUSTOM_THUMBNAIL_ACCEPT = "image/png,image/jpeg,image/webp"; + +const ACCEPTED_SOURCE_TYPES = new Set(CUSTOM_THUMBNAIL_ACCEPT.split(",")); + +export function validateThumbnailSourceFile(file: { + type: string; + size: number; +}): string | null { + if (!ACCEPTED_SOURCE_TYPES.has(file.type.toLowerCase())) { + return "Choose a PNG, JPEG or WebP image"; + } + if (file.size === 0) return "That image is empty"; + if (file.size > CUSTOM_THUMBNAIL_MAX_SOURCE_BYTES) { + return "Choose an image under 20 MB"; + } + return null; +} + +export function isJpegData(data: Uint8Array): boolean { + return ( + data.length > 4 && + data[0] === 0xff && + data[1] === 0xd8 && + data[2] === 0xff && + data[data.length - 2] === 0xff && + data[data.length - 1] === 0xd9 + ); +} + +/** + * Fits `width` x `height` inside the thumbnail bounds without upscaling. + */ +export function fitThumbnailSize(width: number, height: number) { + if (!(width > 0) || !(height > 0)) return null; + const scale = Math.min( + 1, + CUSTOM_THUMBNAIL_MAX_DIMENSION / Math.max(width, height), + ); + return { + width: Math.max(1, Math.round(width * scale)), + height: Math.max(1, Math.round(height * scale)), + }; +} + +/** + * Seconds into the video to take a frame from, kept just inside its end so + * ffmpeg always has a frame to decode. Null for anything that is not a time. + */ +export function clampThumbnailFrameTime( + time: unknown, + duration: number | null | undefined, +): number | null { + if (typeof time !== "number" || !Number.isFinite(time) || time < 0) { + return null; + } + const rounded = Math.round(time * 1000) / 1000; + if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) { + return Math.min(rounded, Math.max(duration - 0.05, 0)); + } + return rounded; +} + +export const CUSTOM_THUMBNAIL_FRAME_FILTER = `scale='min(iw,${CUSTOM_THUMBNAIL_MAX_DIMENSION})':'min(ih,${CUSTOM_THUMBNAIL_MAX_DIMENSION})':force_original_aspect_ratio=decrease:force_divisible_by=2`; diff --git a/apps/web/lib/oembed.ts b/apps/web/lib/oembed.ts index 73ea2929a11..bb30d418b61 100644 --- a/apps/web/lib/oembed.ts +++ b/apps/web/lib/oembed.ts @@ -1,5 +1,6 @@ import { serverEnv } from "@cap/env"; import type { PublicShareVideo } from "@/lib/public-share-video"; +import { buildVideoOgImageUrl } from "@/lib/share-video-metadata"; const DEFAULT_WIDTH = 800; const DEFAULT_HEIGHT = 450; @@ -120,8 +121,11 @@ export const buildOEmbedVideo = ({ maxHeight: parsedMaxHeight, }); const embedUrl = new URL(`/embed/${video.id}`, webUrl).toString(); - const thumbnailUrl = new URL("/api/video/og", webUrl); - thumbnailUrl.searchParams.set("videoId", video.id); + const thumbnailUrl = buildVideoOgImageUrl({ + videoId: video.id, + webUrl, + thumbnailVersion: video.thumbnailVersion, + }); const html = ``; return { @@ -138,7 +142,7 @@ export const buildOEmbedVideo = ({ ...((parsedMaxWidth === undefined || parsedMaxWidth >= 1200) && (parsedMaxHeight === undefined || parsedMaxHeight >= 630) ? { - thumbnail_url: thumbnailUrl.toString(), + thumbnail_url: thumbnailUrl, thumbnail_width: 1200, thumbnail_height: 630, } diff --git a/apps/web/lib/og/poster-frame.ts b/apps/web/lib/og/poster-frame.ts index 80d4566592c..4e450f4469d 100644 --- a/apps/web/lib/og/poster-frame.ts +++ b/apps/web/lib/og/poster-frame.ts @@ -24,11 +24,18 @@ const SOURCE_LADDER = [ { videoType: "raw-preview", seek: "0" }, ]; -const grabFrame = ( +const OG_FRAME_FILTER = "scale=1120:-2"; +const OG_FRAME_QUALITY = "4"; + +export const grabFrame = ( ffmpeg: string, url: string, seek: string, timeoutMs: number, + { + filter = OG_FRAME_FILTER, + quality = OG_FRAME_QUALITY, + }: { filter?: string; quality?: string } = {}, ) => new Promise((resolve, reject) => { const proc = spawn( @@ -45,9 +52,9 @@ const grabFrame = ( "-frames:v", "1", "-vf", - "scale=1120:-2", + filter, "-q:v", - "4", + quality, "-f", "image2pipe", "-vcodec", diff --git a/apps/web/lib/public-share-video.ts b/apps/web/lib/public-share-video.ts index 5ae904e8abf..c4104a5cb79 100644 --- a/apps/web/lib/public-share-video.ts +++ b/apps/web/lib/public-share-video.ts @@ -7,6 +7,7 @@ import { videos, videoUploads, } from "@cap/database/schema"; +import { getCustomThumbnailVersion } from "@cap/web-backend/src/Storage/custom-thumbnail"; import { Video } from "@cap/web-domain"; import { and, eq, isNotNull, isNull, sql } from "drizzle-orm"; @@ -33,6 +34,7 @@ export type PublicShareVideoCandidate = { width: number | null; height: number | null; duration: number | null; + thumbnailVersion?: string | null; }; export type PublicShareVideo = Omit< @@ -91,6 +93,9 @@ export async function getPublicShareVideo( width: videos.width, height: videos.height, duration: videos.duration, + customThumbnailFile: sql< + string | null + >`JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customThumbnail.file'))`, }) .from(videos) .innerJoin( @@ -114,7 +119,8 @@ export async function getPublicShareVideo( .where(and(eq(spaceVideos.videoId, videoId), isNotNull(spaces.password))) .limit(1); - const { videoSettings, organizationSettings, ...rest } = video; + const { videoSettings, organizationSettings, customThumbnailFile, ...rest } = + video; const candidate: PublicShareVideoCandidate = { ...rest, linkOpenToAnyone: Video.isLinkOpenToAnyone( @@ -122,6 +128,9 @@ export async function getPublicShareVideo( organizationSettings, ), hasInheritedPassword: Boolean(inheritedPassword), + thumbnailVersion: getCustomThumbnailVersion({ + customThumbnail: { file: customThumbnailFile }, + }), }; if (!isPublicShareVideoCandidateEligible(candidate)) return null; @@ -135,5 +144,6 @@ export async function getPublicShareVideo( width: candidate.width, height: candidate.height, duration: candidate.duration, + thumbnailVersion: candidate.thumbnailVersion, }; } diff --git a/apps/web/lib/share-playback.ts b/apps/web/lib/share-playback.ts index 50f947f9d89..61e613c13b1 100644 --- a/apps/web/lib/share-playback.ts +++ b/apps/web/lib/share-playback.ts @@ -42,6 +42,29 @@ export const getSharePlaybackSource = ( .pipe(runPromise) .catch(() => null); +/** + * Signs the owner's custom thumbnail, if there is one. Callers only reach for + * this when the video's metadata names one, so other pages pay nothing. + */ +export const getCustomThumbnailUrl = ( + video: SharePlaybackVideo, + key: string, +): Promise => + Effect.gen(function* () { + const loadedVideo = yield* Schema.decodeUnknown(Video.Video)({ + ...video, + ownerId: video.owner.id, + bucketId: video.bucket, + folderId: null, + createdAt: video.createdAt.toISOString(), + updatedAt: video.updatedAt.toISOString(), + }); + const [bucket] = yield* Storage.getAccessForVideo(loadedVideo); + return yield* bucket.getSignedObjectUrl(key); + }) + .pipe(runPromise) + .catch(() => null); + export const getSharePlaybackUrl = (video: SharePlaybackVideo) => getSharePlaybackSource(video).then((source) => source?.url ?? null); diff --git a/apps/web/lib/share-video-metadata.ts b/apps/web/lib/share-video-metadata.ts index 73fb96cd29b..bf0bc7a7a4d 100644 --- a/apps/web/lib/share-video-metadata.ts +++ b/apps/web/lib/share-video-metadata.ts @@ -25,6 +25,26 @@ export type ShareVideoMetadataInput = { */ canonicalWebUrl?: string; advertiseIframelyPlayer?: boolean; + /** + * Set when the owner picked a thumbnail. Link previews then show it instead + * of the animated preview, under a URL that changes with every new pick. + */ + thumbnailVersion?: string | null; +}; + +export const buildVideoOgImageUrl = ({ + videoId, + webUrl, + thumbnailVersion, +}: { + videoId: string; + webUrl: string; + thumbnailVersion?: string | null; +}) => { + const url = new URL("/api/video/og", webUrl); + url.searchParams.set("videoId", videoId); + if (thumbnailVersion) url.searchParams.set("v", thumbnailVersion); + return url.toString(); }; export const getShareVideoUrls = ({ @@ -32,9 +52,10 @@ export const getShareVideoUrls = ({ sourceType, webUrl, canonicalWebUrl = webUrl, + thumbnailVersion, }: Pick< ShareVideoMetadataInput, - "videoId" | "sourceType" | "webUrl" | "canonicalWebUrl" + "videoId" | "sourceType" | "webUrl" | "canonicalWebUrl" | "thumbnailVersion" >) => { const shareUrl = new URL(`/s/${videoId}`, webUrl).toString(); const canonicalShareUrl = new URL( @@ -57,8 +78,11 @@ export const getShareVideoUrls = ({ const previewImageUrl = new URL("/api/video/preview", webUrl); previewImageUrl.searchParams.set("videoId", videoId); previewImageUrl.searchParams.set("fallback", "og"); - const ogImageUrl = new URL("/api/video/og", webUrl); - ogImageUrl.searchParams.set("videoId", videoId); + const ogImageUrl = buildVideoOgImageUrl({ + videoId, + webUrl, + thumbnailVersion, + }); const oEmbedUrl = new URL("/api/oembed", canonicalWebUrl); oEmbedUrl.searchParams.set("url", canonicalShareUrl); oEmbedUrl.searchParams.set("format", "json"); @@ -69,7 +93,7 @@ export const getShareVideoUrls = ({ streamUrl: streamUrl.toString(), streamContentType, previewImageUrl: previewImageUrl.toString(), - ogImageUrl: ogImageUrl.toString(), + ogImageUrl, oEmbedUrl: oEmbedUrl.toString(), }; }; @@ -83,13 +107,21 @@ export const buildShareVideoMetadata = ({ advertiseIframelyPlayer = false, width, height, + thumbnailVersion, }: ShareVideoMetadataInput): Metadata => { const urls = getShareVideoUrls({ videoId, sourceType, webUrl, canonicalWebUrl, + thumbnailVersion, }); + const ogImage = { + url: urls.ogImageUrl, + width: 1200, + height: 630, + type: "image/png", + }; const title = `${name} | Cap Recording`; const description = "Watch this video on Cap"; const hasDimensions = @@ -132,20 +164,17 @@ export const buildShareVideoMetadata = ({ title, description, ttl: 300, - images: [ - { - url: urls.previewImageUrl, - width: 480, - height: 270, - type: "image/gif", - }, - { - url: urls.ogImageUrl, - width: 1200, - height: 630, - type: "image/png", - }, - ], + images: thumbnailVersion + ? [ogImage] + : [ + { + url: urls.previewImageUrl, + width: 480, + height: 270, + type: "image/gif", + }, + ogImage, + ], videos: [ { url: urls.streamUrl, @@ -160,7 +189,9 @@ export const buildShareVideoMetadata = ({ card: "player", title, description, - images: [urls.previewImageUrl, urls.ogImageUrl], + images: thumbnailVersion + ? [urls.ogImageUrl] + : [urls.previewImageUrl, urls.ogImageUrl], players: { playerUrl: urls.playerUrl, streamUrl: urls.streamUrl, diff --git a/apps/web/lib/slack/unfurl.ts b/apps/web/lib/slack/unfurl.ts index 70d902f0d5a..2f99c6cc971 100644 --- a/apps/web/lib/slack/unfurl.ts +++ b/apps/web/lib/slack/unfurl.ts @@ -1,6 +1,7 @@ import { Video } from "@cap/web-domain"; import { parseCapShareUrl } from "@/lib/oembed"; import { formatClock } from "@/lib/player-time"; +import { buildVideoOgImageUrl } from "@/lib/share-video-metadata"; import { getPublicShareVideo, type PublicShareVideo, @@ -58,8 +59,11 @@ export const buildSlackVideoBlock = ({ const embedUrl = new URL(`/embed/${video.id}`, webUrl); embedUrl.searchParams.set("autoplay", "true"); embedUrl.searchParams.set("slack", "true"); - const thumbnailUrl = new URL("/api/video/og", webUrl); - thumbnailUrl.searchParams.set("videoId", video.id); + const thumbnailUrl = buildVideoOgImageUrl({ + videoId: video.id, + webUrl, + thumbnailVersion: video.thumbnailVersion, + }); return { type: "video", @@ -76,7 +80,7 @@ export const buildSlackVideoBlock = ({ }, video_url: embedUrl.toString(), alt_text: truncate(`Watch ${video.name}`, 200), - thumbnail_url: thumbnailUrl.toString(), + thumbnail_url: thumbnailUrl, provider_name: "Cap", ...(video.ownerName ? { author_name: truncate(video.ownerName, 49) } : {}), }; diff --git a/packages/database/types/metadata.ts b/packages/database/types/metadata.ts index 734d7754ff1..0648236d63c 100644 --- a/packages/database/types/metadata.ts +++ b/packages/database/types/metadata.ts @@ -132,6 +132,16 @@ export interface VideoMetadata { state: "pending" | "accepted" | "rejected"; rawFileKey?: string; }; + /** + * Thumbnail the owner picked. `file` lives under + * `//thumbnail/` and changes with every pick. + */ + customThumbnail?: { + file: string; + source: "upload" | "frame"; + time?: number; + updatedAt: string; + }; } export interface VideoCallToAction { diff --git a/packages/web-backend/src/Storage/custom-thumbnail.ts b/packages/web-backend/src/Storage/custom-thumbnail.ts new file mode 100644 index 00000000000..1fd30924366 --- /dev/null +++ b/packages/web-backend/src/Storage/custom-thumbnail.ts @@ -0,0 +1,72 @@ +export const CUSTOM_THUMBNAIL_DIRECTORY = "thumbnail"; + +const CUSTOM_THUMBNAIL_FILE_PATTERN = /^custom-[0-9a-z]{1,32}\.jpg$/; + +export type CustomThumbnailMetadata = { + file: string; + source: "upload" | "frame"; + time?: number; + updatedAt: string; +}; + +type CustomThumbnailVideo = { + id: string; + ownerId: string; + metadata: unknown; +}; + +function isRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +export function isCustomThumbnailFileName(file: unknown): file is string { + return typeof file === "string" && CUSTOM_THUMBNAIL_FILE_PATTERN.test(file); +} + +export function getCustomThumbnailMetadata( + metadata: unknown, +): CustomThumbnailMetadata | null { + if (!isRecord(metadata)) return null; + const value = metadata.customThumbnail; + if (!isRecord(value) || !isCustomThumbnailFileName(value.file)) return null; + return { + file: value.file, + source: value.source === "frame" ? "frame" : "upload", + ...(typeof value.time === "number" && Number.isFinite(value.time) + ? { time: value.time } + : {}), + updatedAt: typeof value.updatedAt === "string" ? value.updatedAt : "", + }; +} + +/** + * The thumbnail the owner picked, stored under the video's own prefix so + * deleting or duplicating the video carries it along like every other object. + * The metadata only holds the file name, never a full key. + */ +export function customThumbnailKey(video: { + id: string; + ownerId: string; + file: string; +}) { + return `${video.ownerId}/${video.id}/${CUSTOM_THUMBNAIL_DIRECTORY}/${video.file}`; +} + +export function getCustomThumbnailKey(video: CustomThumbnailVideo) { + const custom = getCustomThumbnailMetadata(video.metadata); + if (!custom) return undefined; + return customThumbnailKey({ + id: video.id, + ownerId: video.ownerId, + file: custom.file, + }); +} + +/** + * Changes whenever the custom thumbnail does, so URLs that embed it (link + * preview images) miss every cache the moment the owner picks a new one. + */ +export function getCustomThumbnailVersion(metadata: unknown) { + const custom = getCustomThumbnailMetadata(metadata); + return custom ? custom.file.slice("custom-".length, -".jpg".length) : null; +} diff --git a/packages/web-backend/src/Videos/index.ts b/packages/web-backend/src/Videos/index.ts index 9a04261344e..91471c254ea 100644 --- a/packages/web-backend/src/Videos/index.ts +++ b/packages/web-backend/src/Videos/index.ts @@ -17,6 +17,7 @@ import type { Schema } from "effect/Schema"; import { Database } from "../Database.ts"; import { Storage as StorageService } from "../Storage/index.ts"; +import { getCustomThumbnailKey } from "../Storage/custom-thumbnail.ts"; import { getPublishedRecordingThumbnailKey } from "../Storage/recording-output.ts"; import { Tinybird } from "../Tinybird/index.ts"; import { getDuplicateVideoMetadata, planVideoDuplicate } from "./duplicate.ts"; @@ -258,6 +259,14 @@ export class Videos extends Effect.Service()("Videos", { const getThumbnailURLForVideo = Effect.fn("Videos.getThumbnailURLForVideo")( function* (video: Video.Video) { const [bucket] = yield* storage.getAccessForVideo(video); + const customThumbnail = getCustomThumbnailKey({ + id: video.id, + ownerId: video.ownerId, + metadata: Option.getOrNull(video.metadata), + }); + if (customThumbnail) { + return Option.some(yield* bucket.getSignedObjectUrl(customThumbnail)); + } const publishedThumbnail = getPublishedRecordingThumbnailKey(video); if (publishedThumbnail) { return Option.some( diff --git a/packages/web-backend/src/index.ts b/packages/web-backend/src/index.ts index 9cbf5176975..c60d459b679 100644 --- a/packages/web-backend/src/index.ts +++ b/packages/web-backend/src/index.ts @@ -38,6 +38,7 @@ export { type ViewerSettingKey, type ViewerSettings, } from "./Videos/EffectiveVideoRules.ts"; +export * from "./Storage/custom-thumbnail.ts"; export { findScreenshotObjectKey, Videos } from "./Videos/index.ts"; export { VideoDownloadGate } from "./Videos/VideoDownloadGate.ts"; export { From 1e3159488c73a2747b9320682d7d57583ed6a9b4 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:47:18 +0000 Subject: [PATCH 03/13] feat(web): embed options for title, owner, logo and autoplay --- apps/web/__tests__/unit/embed-options.test.ts | 167 ++++++++++++++++++ .../caps/components/SharingDialog.tsx | 35 +++- .../[videoId]/_components/ShareLinkDialog.tsx | 28 ++- .../components/embed/EmbedOptionsFields.tsx | 92 ++++++++++ apps/web/lib/embed-code.ts | 18 +- apps/web/lib/embed-options.ts | 77 ++++++++ 6 files changed, 406 insertions(+), 11 deletions(-) create mode 100644 apps/web/__tests__/unit/embed-options.test.ts create mode 100644 apps/web/components/embed/EmbedOptionsFields.tsx create mode 100644 apps/web/lib/embed-options.ts diff --git a/apps/web/__tests__/unit/embed-options.test.ts b/apps/web/__tests__/unit/embed-options.test.ts new file mode 100644 index 00000000000..147d934cec6 --- /dev/null +++ b/apps/web/__tests__/unit/embed-options.test.ts @@ -0,0 +1,167 @@ +import { describe, expect, it } from "vitest"; +import { buildEmbedCode } from "@/lib/embed-code"; +import { + buildEmbedQuery, + DEFAULT_EMBED_OPTIONS, + parseEmbedOptions, +} from "@/lib/embed-options"; + +const legacyBuildEmbedCode = ({ + webUrl, + videoId, + startTime, +}: { + webUrl: string; + videoId: string; + startTime?: number | null; +}): string => { + const start = + typeof startTime === "number" && Number.isFinite(startTime) && startTime > 0 + ? `?t=${Math.floor(startTime)}` + : ""; + + return ` +
+ +
+` + .trim() + .replace(/[\n\t]+/g, " ") + .replace(/>\s+<") + .replace(/"\s+>/g, '">'); +}; + +describe("parseEmbedOptions", () => { + it("defaults to how embeds have always looked", () => { + expect(parseEmbedOptions({})).toEqual(DEFAULT_EMBED_OPTIONS); + expect(parseEmbedOptions(null)).toEqual(DEFAULT_EMBED_OPTIONS); + expect(parseEmbedOptions(new URLSearchParams(""))).toEqual( + DEFAULT_EMBED_OPTIONS, + ); + }); + + it("only hides things on an explicit false", () => { + expect( + parseEmbedOptions({ title: "false", owner: "0", branding: "false" }), + ).toMatchObject({ showTitle: false, showOwner: false, showBranding: false }); + expect( + parseEmbedOptions({ title: "no", owner: "", branding: "true" }), + ).toMatchObject({ showTitle: true, showOwner: true, showBranding: true }); + }); + + it("only autoplays and mutes on an explicit true", () => { + expect(parseEmbedOptions({ autoplay: "true", muted: "1" })).toMatchObject({ + autoplay: true, + muted: true, + }); + expect(parseEmbedOptions({ autoplay: "yes", muted: "false" })).toMatchObject( + { autoplay: false, muted: false }, + ); + }); + + it("keeps the existing start time rules", () => { + expect(parseEmbedOptions({ t: "83" }).startTime).toBe(83); + expect(parseEmbedOptions({ t: ["12", "40"] }).startTime).toBe(12); + for (const t of ["0", "-5", "abc", ""]) { + expect(parseEmbedOptions({ t }).startTime).toBeNull(); + } + }); + + it("takes the first of repeated params", () => { + expect( + parseEmbedOptions({ title: ["false", "true"] }).showTitle, + ).toBe(false); + expect( + parseEmbedOptions(new URLSearchParams("title=true&title=false")) + .showTitle, + ).toBe(true); + }); +}); + +describe("buildEmbedQuery", () => { + it("is empty for defaults", () => { + expect(buildEmbedQuery({})).toBe(""); + expect(buildEmbedQuery(DEFAULT_EMBED_OPTIONS)).toBe(""); + }); + + it("writes only changed options, in a fixed order", () => { + expect( + buildEmbedQuery({ + showBranding: false, + showTitle: false, + autoplay: true, + muted: true, + showOwner: false, + startTime: 61.9, + }), + ).toBe( + "?t=61&autoplay=true&muted=true&title=false&owner=false&branding=false", + ); + }); + + it("round trips through the parser", () => { + const options = { + ...DEFAULT_EMBED_OPTIONS, + showOwner: false, + autoplay: true, + muted: true, + startTime: 30, + }; + expect( + parseEmbedOptions(new URLSearchParams(buildEmbedQuery(options))), + ).toEqual(options); + }); +}); + +describe("buildEmbedCode", () => { + it("is byte-identical to the previous snippet with default options", () => { + const cases = [ + { webUrl: "https://cap.so", videoId: "abc123" }, + { webUrl: "https://cap.so", videoId: "abc123", startTime: 83 }, + { webUrl: "https://cap.so", videoId: "abc123", startTime: 83.7 }, + { webUrl: "https://cap.so", videoId: "abc123", startTime: null }, + { webUrl: "https://cap.example.com", videoId: "xyz", startTime: 0 }, + ]; + for (const input of cases) { + expect(buildEmbedCode(input)).toBe(legacyBuildEmbedCode(input)); + expect(buildEmbedCode({ ...input, options: {} })).toBe( + legacyBuildEmbedCode(input), + ); + } + expect(buildEmbedCode({ webUrl: "https://cap.so", videoId: "abc123" })).toBe( + '
', + ); + }); + + it("adds the options and delegates autoplay to the iframe", () => { + const code = buildEmbedCode({ + webUrl: "https://cap.so", + videoId: "abc123", + startTime: 10, + options: { autoplay: true, muted: true, showTitle: false }, + }); + expect(code).toContain( + 'src="https://cap.so/embed/abc123?t=10&autoplay=true&muted=true&title=false"', + ); + expect(code).toContain( + 'frameborder="0" allow="autoplay; fullscreen; picture-in-picture" webkitallowfullscreen', + ); + }); + + it("does not add the allow attribute without autoplay", () => { + const code = buildEmbedCode({ + webUrl: "https://cap.so", + videoId: "abc123", + options: { showBranding: false }, + }); + expect(code).not.toContain("allow="); + expect(code).toContain('src="https://cap.so/embed/abc123?branding=false"'); + }); +}); diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx index 1c4cf40fc2c..12d1e50be0d 100644 --- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx +++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx @@ -37,6 +37,11 @@ import type { Spaces } from "@/app/(org)/dashboard/dashboard-data"; import type { CurrentUser } from "@/app/Layout/AuthContext"; import { FontAwesomeIcon } from "@/components/FontAwesomeIcon"; import { SignedImageUrl } from "@/components/SignedImageUrl"; +import { + DEFAULT_EMBED_TOGGLES, + EmbedOptionsFields, + embedTogglesToOptions, +} from "@/components/embed/EmbedOptionsFields"; import { buildEmbedCode } from "@/lib/embed-code"; import { videoShareUrl } from "@/lib/video-share-url"; import { usePublicEnv } from "@/utils/public-env"; @@ -362,7 +367,15 @@ export const SharingDialog: React.FC = ({ }); }; - const embedCode = useEmbedCode(capId); + const [embedToggles, setEmbedToggles] = useState(DEFAULT_EMBED_TOGGLES); + const canHideEmbedBranding = Boolean(user?.isPro); + const embedCode = useEmbedCode( + capId, + embedTogglesToOptions({ + ...embedToggles, + showBranding: canHideEmbedBranding ? embedToggles.showBranding : true, + }), + ); const handleCopyEmbedCode = async () => { try { @@ -720,6 +733,11 @@ export const SharingDialog: React.FC = ({ {embedCode}
+
+

Paste this wherever HTML is allowed. The player keeps its aspect ratio and fills the width it's given. diff --git a/apps/web/components/embed/EmbedOptionsFields.tsx b/apps/web/components/embed/EmbedOptionsFields.tsx new file mode 100644 index 00000000000..2737dbf0b1e --- /dev/null +++ b/apps/web/components/embed/EmbedOptionsFields.tsx @@ -0,0 +1,92 @@ +"use client"; + +import { Switch } from "@cap/ui"; +import { useId } from "react"; +import type { EmbedOptions } from "@/lib/embed-options"; + +export type EmbedToggleOptions = Pick< + EmbedOptions, + "showTitle" | "showOwner" | "showBranding" | "autoplay" +>; + +export const DEFAULT_EMBED_TOGGLES: EmbedToggleOptions = { + showTitle: true, + showOwner: true, + showBranding: true, + autoplay: false, +}; + +/** + * Autoplay only works muted in browsers, so the toggle sets both. + */ +export const embedTogglesToOptions = ( + toggles: EmbedToggleOptions, +): Partial> => ({ + ...toggles, + muted: toggles.autoplay, +}); + +const ROWS: { + key: keyof EmbedToggleOptions; + label: string; + description?: string; + pro?: boolean; +}[] = [ + { key: "showTitle", label: "Title" }, + { key: "showOwner", label: "Owner" }, + { key: "showBranding", label: "Logo", pro: true }, + { + key: "autoplay", + label: "Autoplay", + description: "Starts muted, as browsers require", + }, +]; + +export function EmbedOptionsFields({ + value, + onChange, + canHideBranding, +}: { + value: EmbedToggleOptions; + onChange: (value: EmbedToggleOptions) => void; + canHideBranding: boolean; +}) { + const id = useId(); + return ( +

+ Embed options + {ROWS.map((row) => { + const locked = row.pro === true && !canHideBranding; + const inputId = `${id}-${row.key}`; + return ( +
+ + onChange({ ...value, [row.key]: checked }) + } + /> + +
+ ); + })} +
+ ); +} diff --git a/apps/web/lib/embed-code.ts b/apps/web/lib/embed-code.ts index 1b9bc4112ae..2a4ed0381b2 100644 --- a/apps/web/lib/embed-code.ts +++ b/apps/web/lib/embed-code.ts @@ -1,3 +1,5 @@ +import { buildEmbedQuery, type EmbedOptions } from "@/lib/embed-options"; + /** * The `
', ); }); 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 ae051cee327..e9cba262dc8 100644 --- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx +++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx @@ -30,8 +30,8 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import clsx from "clsx"; import { Effect, Option } from "effect"; import { FolderInput } from "lucide-react"; -import Link from "next/link"; import dynamic from "next/dynamic"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { type PropsWithChildren, useEffect, useRef, useState } from "react"; import { toast } from "sonner"; diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx index 12d1e50be0d..8482342b843 100644 --- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx +++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx @@ -35,13 +35,13 @@ import { import { useDashboardContext } from "@/app/(org)/dashboard/Contexts"; import type { Spaces } from "@/app/(org)/dashboard/dashboard-data"; import type { CurrentUser } from "@/app/Layout/AuthContext"; -import { FontAwesomeIcon } from "@/components/FontAwesomeIcon"; -import { SignedImageUrl } from "@/components/SignedImageUrl"; import { DEFAULT_EMBED_TOGGLES, EmbedOptionsFields, embedTogglesToOptions, } from "@/components/embed/EmbedOptionsFields"; +import { FontAwesomeIcon } from "@/components/FontAwesomeIcon"; +import { SignedImageUrl } from "@/components/SignedImageUrl"; import { buildEmbedCode } from "@/lib/embed-code"; import { videoShareUrl } from "@/lib/video-share-url"; import { usePublicEnv } from "@/utils/public-env"; @@ -856,6 +856,14 @@ function useEmbedCode( videoId: capId, options: { showTitle, showOwner, showBranding, autoplay, muted }, }), - [publicEnv.webUrl, capId, showTitle, showOwner, showBranding, autoplay, muted], + [ + publicEnv.webUrl, + capId, + showTitle, + showOwner, + showBranding, + autoplay, + muted, + ], ); } diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx index 9c354b6f695..6f1627f8084 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx @@ -99,11 +99,8 @@ export const ShareableLinkBrandColor = () => { >
-
+
+ Brand colour { )} -
+
); } diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx index 30dbe50eb8e..365d6259caa 100644 --- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx +++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx @@ -336,63 +336,65 @@ export const EmbedVideo = forwardRef< {!isPlaying && (
{(showTitle || (showOwner && ownerName)) && ( - -
- {showOwner && ownerName && ( - - )} -
- {showTitle && ( - e.stopPropagation()} - > -

- {data.name} -

-
+ +
+ {showOwner && ownerName && ( + )} -
- {showOwner && ownerName && ( -

- {ownerName} -

+
+ {showTitle && ( + e.stopPropagation()} + > +

+ {data.name} +

+
)} - {(showOwner ? Boolean(ownerName) : showTitle) && - longestDuration > 0 && ( - <> - {showOwner && ( - • - )} -

- {formatPlayerTime(longestDuration)} -

- +
+ {showOwner && ownerName && ( +

+ {ownerName} +

)} + {(showOwner ? Boolean(ownerName) : showTitle) && + longestDuration > 0 && ( + <> + {showOwner && ( + + • + + )} +

+ {formatPlayerTime(longestDuration)} +

+ + )} +
-
-
+ )} {branding?.type === "custom" ? ( - +
); } diff --git a/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx b/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx index 92e45a7272f..472ab75e48b 100644 --- a/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx +++ b/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx @@ -5,17 +5,17 @@ import clsx from "clsx"; import { Check, CodeXml, Link2, Lock, Megaphone, X } from "lucide-react"; import { useCallback, useEffect, useMemo, useState } from "react"; import { toast } from "sonner"; +import { + DEFAULT_EMBED_TOGGLES, + EmbedOptionsFields, + embedTogglesToOptions, +} from "@/components/embed/EmbedOptionsFields"; import { FacebookIcon, GoogleIcon, LinkedInIcon, XIcon, } from "@/components/icons/Social"; -import { - DEFAULT_EMBED_TOGGLES, - EmbedOptionsFields, - embedTogglesToOptions, -} from "@/components/embed/EmbedOptionsFields"; import { buildEmbedCode } from "@/lib/embed-code"; import { type ShareTargetId, diff --git a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx index 71ae36b236f..1dcdf08971e 100644 --- a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx +++ b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx @@ -56,7 +56,8 @@ function formFromCallToAction( cta: ShareCallToAction | null, brandColor: string | null, ): FormState { - if (!cta) return brandColor ? { ...EMPTY_FORM, color: brandColor } : EMPTY_FORM; + if (!cta) + return brandColor ? { ...EMPTY_FORM, color: brandColor } : EMPTY_FORM; return { label: cta.label, url: cta.url, @@ -711,7 +712,8 @@ function ColorPicker({ }) { const normalized = normalizeHexColor(value) ?? DEFAULT_CTA_COLOR; const presets = - brandColor && !CTA_COLOR_PRESETS.some((preset) => preset.value === brandColor) + brandColor && + !CTA_COLOR_PRESETS.some((preset) => preset.value === brandColor) ? [{ name: "Brand", value: brandColor }, ...CTA_COLOR_PRESETS] : CTA_COLOR_PRESETS; const isCustom = !presets.some((preset) => preset.value === normalized); diff --git a/apps/web/lib/custom-thumbnail.ts b/apps/web/lib/custom-thumbnail.ts index 223f208a713..61e404634f4 100644 --- a/apps/web/lib/custom-thumbnail.ts +++ b/apps/web/lib/custom-thumbnail.ts @@ -65,7 +65,11 @@ export function clampThumbnailFrameTime( return null; } const rounded = Math.round(time * 1000) / 1000; - if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) { + if ( + typeof duration === "number" && + Number.isFinite(duration) && + duration > 0 + ) { return Math.min(rounded, Math.max(duration - 0.05, 0)); } return rounded; diff --git a/apps/web/lib/embed-options.ts b/apps/web/lib/embed-options.ts index c1a52fdaf84..b95065e536e 100644 --- a/apps/web/lib/embed-options.ts +++ b/apps/web/lib/embed-options.ts @@ -31,8 +31,7 @@ const readParam = (params: SearchParamsInput, key: string) => { return Array.isArray(value) ? value[0] : value; }; -const isOff = (value: string | undefined) => - value === "false" || value === "0"; +const isOff = (value: string | undefined) => value === "false" || value === "0"; const isOn = (value: string | undefined) => value === "true" || value === "1"; const parseStartTime = (value: string | undefined) => { diff --git a/apps/web/lib/slack/unfurl.ts b/apps/web/lib/slack/unfurl.ts index 2f99c6cc971..d3984d556af 100644 --- a/apps/web/lib/slack/unfurl.ts +++ b/apps/web/lib/slack/unfurl.ts @@ -1,11 +1,11 @@ import { Video } from "@cap/web-domain"; import { parseCapShareUrl } from "@/lib/oembed"; import { formatClock } from "@/lib/player-time"; -import { buildVideoOgImageUrl } from "@/lib/share-video-metadata"; import { getPublicShareVideo, type PublicShareVideo, } from "@/lib/public-share-video"; +import { buildVideoOgImageUrl } from "@/lib/share-video-metadata"; import { sendSlackUnfurl } from "./client"; import { deleteSlackInstallationByTeamId, diff --git a/packages/web-backend/src/Videos/index.ts b/packages/web-backend/src/Videos/index.ts index 91471c254ea..20c09544688 100644 --- a/packages/web-backend/src/Videos/index.ts +++ b/packages/web-backend/src/Videos/index.ts @@ -16,8 +16,8 @@ import { Array as Arr, Cause, Effect, Exit, Option } from "effect"; import type { Schema } from "effect/Schema"; import { Database } from "../Database.ts"; -import { Storage as StorageService } from "../Storage/index.ts"; import { getCustomThumbnailKey } from "../Storage/custom-thumbnail.ts"; +import { Storage as StorageService } from "../Storage/index.ts"; import { getPublishedRecordingThumbnailKey } from "../Storage/recording-output.ts"; import { Tinybird } from "../Tinybird/index.ts"; import { getDuplicateVideoMetadata, planVideoDuplicate } from "./duplicate.ts"; diff --git a/packages/web-backend/src/index.ts b/packages/web-backend/src/index.ts index c60d459b679..742ad3c7ae1 100644 --- a/packages/web-backend/src/index.ts +++ b/packages/web-backend/src/index.ts @@ -15,6 +15,7 @@ export { S3Buckets } from "./S3Buckets/index.ts"; export { Spaces } from "./Spaces/index.ts"; export { SpacesPolicy } from "./Spaces/SpacesPolicy.ts"; export { attachmentContentDisposition } from "./Storage/content-disposition.ts"; +export * from "./Storage/custom-thumbnail.ts"; export * from "./Storage/GoogleDrive.ts"; export { Storage } from "./Storage/index.ts"; export { @@ -38,7 +39,6 @@ export { type ViewerSettingKey, type ViewerSettings, } from "./Videos/EffectiveVideoRules.ts"; -export * from "./Storage/custom-thumbnail.ts"; export { findScreenshotObjectKey, Videos } from "./Videos/index.ts"; export { VideoDownloadGate } from "./Videos/VideoDownloadGate.ts"; export { From cd6ca4305ee37eb71834fdca3ef21a322a5ba749 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:05:22 +0000 Subject: [PATCH 06/13] fix(web): apply the embed brand colour on the player container --- .../[videoId]/_components/EmbedVideo.tsx | 4 + apps/web/app/embed/[videoId]/page.tsx | 73 +++++++++---------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx index 365d6259caa..4c135b7a081 100644 --- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx +++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx @@ -23,6 +23,7 @@ import { } from "@/app/s/[videoId]/_components/RecordingInProgress"; import type { UploadProgress } from "@/app/s/[videoId]/_components/upload-progress"; import { formatChaptersAsVTT } from "@/app/s/[videoId]/_components/utils/transcript-utils"; +import { type PlayerBrand, playerBrandAttributes } from "@/lib/player-brand"; import { formatPlayerTime } from "@/lib/player-time"; import type { SharePageBranding } from "@/lib/share-branding"; import type { ShareCallToAction } from "@/lib/share-call-to-action"; @@ -61,6 +62,7 @@ export const EmbedVideo = forwardRef< }; branding: SharePageBranding | null; posterUrl?: string | null; + playerBrand?: PlayerBrand | null; user: typeof userSelectProps | null; comments: CommentWithAuthor[]; chapters?: { title: string; start: number }[]; @@ -84,6 +86,7 @@ export const EmbedVideo = forwardRef< data, branding, posterUrl = null, + playerBrand = null, user: _user, comments: _comments, chapters = [], @@ -273,6 +276,7 @@ export const EmbedVideo = forwardRef< <>
setIsPlaying(true)} onPauseCapture={() => setIsPlaying(false)} diff --git a/apps/web/app/embed/[videoId]/page.tsx b/apps/web/app/embed/[videoId]/page.tsx index fc825b153d6..04367bae621 100644 --- a/apps/web/app/embed/[videoId]/page.tsx +++ b/apps/web/app/embed/[videoId]/page.tsx @@ -38,7 +38,7 @@ import { startDeferredLoomProcessing, } from "@/lib/loom-deferred-processing"; import { resolveDefaultPlaybackSpeed } from "@/lib/playback-speed"; -import { getPlayerBrand, playerBrandAttributes } from "@/lib/player-brand"; +import { getPlayerBrand } from "@/lib/player-brand"; import * as EffectRuntime from "@/lib/server"; import { getSharePageBranding } from "@/lib/share-branding"; import { parseShareCallToAction } from "@/lib/share-call-to-action"; @@ -423,44 +423,41 @@ async function EmbedContent({ ], ); - const brandAttributes = playerBrandAttributes( - getPlayerBrand({ - ownerIsPro: ownerIsProUser, - organizationMetadata, - }), - ); + const playerBrand = getPlayerBrand({ + ownerIsPro: ownerIsProUser, + organizationMetadata, + }); return ( -
- -
+ ); } From 4599f85e087dc07375a2bc2f38f829352b41ac1e Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:28:05 +0000 Subject: [PATCH 07/13] test(web): mock the brand colour row in the organization details test --- .../__tests__/unit/organization-settings-ownership.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/web/__tests__/unit/organization-settings-ownership.test.ts b/apps/web/__tests__/unit/organization-settings-ownership.test.ts index ecab49c45de..ff06b1696b3 100644 --- a/apps/web/__tests__/unit/organization-settings-ownership.test.ts +++ b/apps/web/__tests__/unit/organization-settings-ownership.test.ts @@ -93,6 +93,10 @@ vi.mock( "@/app/(org)/dashboard/settings/organization/components/ShareableLinkIcon", () => ({ ShareableLinkIcon: () => null }), ); +vi.mock( + "@/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor", + () => ({ ShareableLinkBrandColor: () => null }), +); vi.mock( "@/app/(org)/dashboard/settings/organization/components/AccessEmailDomain", () => ({ default: () => null }), From 77615a1974062e4ef1660a810da2b5933ee7e32e Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 17 Nov 2026 01:19:23 +0000 Subject: [PATCH 08/13] fix(web): focus the active tab when the thumbnail dialog opens --- .../organization/components/ShareableLinkBrandColor.tsx | 2 +- .../components/custom-thumbnail/CustomThumbnailDialog.tsx | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx index 6f1627f8084..1c8888d1650 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx @@ -203,7 +203,7 @@ export const ShareableLinkBrandColor = () => { : brand && !brand.accent ? "This colour is too dark to see on video, so the progress bar and focus rings stay white. The play button uses it." : brand - ? `Play button text is ${brand.foreground === "#FFFFFF" ? "white" : "dark"} so it stays readable.` + ? `The play icon is ${brand.foreground === "#FFFFFF" ? "white" : "dark"} on this colour so it stays readable.` : "Share pages and embeds use Cap blue."}

diff --git a/apps/web/components/custom-thumbnail/CustomThumbnailDialog.tsx b/apps/web/components/custom-thumbnail/CustomThumbnailDialog.tsx index 7a003f0abbe..7afe007fd41 100644 --- a/apps/web/components/custom-thumbnail/CustomThumbnailDialog.tsx +++ b/apps/web/components/custom-thumbnail/CustomThumbnailDialog.tsx @@ -85,6 +85,7 @@ export function CustomThumbnailDialog({ const busy = pending !== null; const videoRef = useRef(null); + const tablistRef = useRef(null); const [videoState, setVideoState] = useState<"loading" | "ready" | "error">( "loading", ); @@ -216,6 +217,12 @@ export function CustomThumbnailDialog({ { + event.preventDefault(); + tablistRef.current + ?.querySelector("[aria-selected=true]") + ?.focus({ preventScroll: true }); + }} className="flex max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] max-w-[600px] flex-col overflow-hidden rounded-2xl border border-gray-4 bg-gray-1" >
@@ -243,6 +250,7 @@ export function CustomThumbnailDialog({
Date: Tue, 17 Nov 2026 01:34:36 +0000 Subject: [PATCH 09/13] feat(web): offer the brand colour in the workspace default call to action --- .../settings/organization/components/DefaultCallToAction.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/DefaultCallToAction.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/DefaultCallToAction.tsx index 5cce0a9b47e..c03bb14b8c4 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/DefaultCallToAction.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/DefaultCallToAction.tsx @@ -4,12 +4,12 @@ import { MousePointer2 } from "lucide-react"; import dynamic from "next/dynamic"; import { useRouter } from "next/navigation"; import { useState } from "react"; +import { playerColorFromOrganizationMetadata } from "@/lib/player-brand"; import { callToActionDestinationLabel, parseWorkspaceCallToAction, readableTextColor, } from "@/lib/share-call-to-action"; -import { playerColorFromOrganizationMetadata } from "@/lib/player-brand"; import { useDashboardContext } from "../../../Contexts"; import { ProChip, From ba948c9ae53eefb66dbb79a223cec8eef40ea4fb Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 17 Nov 2026 01:57:52 +0000 Subject: [PATCH 10/13] fix(web): carry the brand focus ring into the player control bar --- apps/web/app/globals.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css index 7a576d47918..ccd4b2743a1 100644 --- a/apps/web/app/globals.css +++ b/apps/web/app/globals.css @@ -1217,6 +1217,9 @@ footer a { background-color: var(--player-brand-accent); } -[data-player-brand-accent] [data-slot="media-player"] { +/* The control bar scopes its own `.dark`, which resets `--ring`, so it needs + the brand ring set again. Light bars (the timeline deck) keep Cap's ring. */ +[data-player-brand-accent] [data-slot="media-player"], +[data-player-brand-accent] [data-slot="media-player-controls"].dark { --ring: var(--player-brand-ring); } From fe01e46ae68a9ba34a064eb043faa64160f4bc78 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 17 Nov 2026 01:57:52 +0000 Subject: [PATCH 11/13] fix(web): redirect link preview versions that do not match the thumbnail --- .../web/__tests__/unit/video-og-route.test.ts | 42 +++++++++++++++++++ apps/web/actions/videos/get-og-image.tsx | 25 ++++++++++- apps/web/app/api/video/og/route.tsx | 7 ++-- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/apps/web/__tests__/unit/video-og-route.test.ts b/apps/web/__tests__/unit/video-og-route.test.ts index 6a526cd739d..a6785706d2b 100644 --- a/apps/web/__tests__/unit/video-og-route.test.ts +++ b/apps/web/__tests__/unit/video-og-route.test.ts @@ -160,6 +160,48 @@ describe("/api/video/og", () => { expect(mocks.lookups).toEqual(["abc123"]); }); + it("renders only the version a video actually has", async () => { + const base = { + ownerId: "owner", + name: "Quarterly update", + public: true, + password: null, + duration: 42, + }; + mocks.videos.set("abc123", { + ...base, + id: "abc123", + metadata: { customThumbnail: { file: "custom-lz9k2a.jpg" } }, + }); + mocks.videos.set("plain1", { ...base, id: "plain1", metadata: null }); + mocks.videos.set("locked1", { + ...base, + id: "locked1", + public: false, + metadata: { customThumbnail: { file: "custom-lz9k2a.jpg" } }, + }); + const GET = await loadRoute(); + + const current = await fetchOg(GET, "?videoId=abc123&v=lz9k2a"); + expect(current.status).toBe(200); + expect(current.headers["content-type"]).toBe("image/png"); + + for (const [query, location] of [ + ["?videoId=abc123&v=old1", "/api/video/og?videoId=abc123&v=lz9k2a"], + ["?videoId=plain1&v=lz9k2a", "/api/video/og?videoId=plain1"], + ] as const) { + const renders = mocks.renders; + const response = await fetchOg(GET, query); + expect(response.status).toBe(307); + expect(response.headers.location).toBe(location); + expect(mocks.renders).toBe(renders); + } + + const locked = await fetchOg(GET, "?videoId=locked1&v=old1"); + expect(locked.status).toBe(200); + expect(locked.headers.location).toBeUndefined(); + }); + it("renders the preview URL the app generates for a public video", async () => { mocks.videos.set("abc123", { id: "abc123", diff --git a/apps/web/actions/videos/get-og-image.tsx b/apps/web/actions/videos/get-og-image.tsx index 0fcb53daadd..c105acd1b33 100644 --- a/apps/web/actions/videos/get-og-image.tsx +++ b/apps/web/actions/videos/get-og-image.tsx @@ -1,7 +1,10 @@ import { db } from "@cap/database"; import { users, videos } from "@cap/database/schema"; import { findScreenshotObjectKey, Storage } from "@cap/web-backend"; -import { getCustomThumbnailKey } from "@cap/web-backend/src/Storage/custom-thumbnail"; +import { + getCustomThumbnailKey, + getCustomThumbnailVersion, +} from "@cap/web-backend/src/Storage/custom-thumbnail"; import { getPublishedRecordingThumbnailKey } from "@cap/web-backend/src/Storage/recording-output"; import type { Video } from "@cap/web-domain"; import { eq } from "drizzle-orm"; @@ -11,7 +14,10 @@ import { renderVideoOg, renderVideoOgStatus } from "@/lib/og/video-og"; import { runPromise } from "@/lib/server"; import { decodeStorageVideo } from "@/lib/video-storage"; -export async function generateVideoOgImage(videoId: Video.VideoId) { +export async function generateVideoOgImage( + videoId: Video.VideoId, + requestedVersion: string | null = null, +) { const videoData = await getData(videoId); if (!videoData) return renderVideoOgStatus("not-found"); @@ -21,6 +27,21 @@ export async function generateVideoOgImage(videoId: Video.VideoId) { if (video.password) return renderVideoOgStatus("password"); if (video.public === false) return renderVideoOgStatus("locked"); + // A version only names an image that exists. Anything else goes to the + // current URL, so made-up versions cannot each cost a fresh render. + const currentVersion = getCustomThumbnailVersion(video.metadata); + if (requestedVersion !== null && requestedVersion !== currentVersion) { + const location = new URLSearchParams({ videoId }); + if (currentVersion) location.set("v", currentVersion); + return new Response(null, { + status: 307, + headers: { + Location: `/api/video/og?${location}`, + "Cache-Control": "public, max-age=60", + }, + }); + } + let screenshotUrl: string | undefined; try { diff --git a/apps/web/app/api/video/og/route.tsx b/apps/web/app/api/video/og/route.tsx index 33d3104f498..1afb4b7c942 100644 --- a/apps/web/app/api/video/og/route.tsx +++ b/apps/web/app/api/video/og/route.tsx @@ -16,8 +16,6 @@ export async function GET(req: NextRequest) { return renderVideoOgStatus("not-found"); } - // `v` only versions the URL so a new custom thumbnail misses every cache; - // anything else collapses to the canonical URL. const version = params.get("v"); const canonical = new URLSearchParams({ videoId }); if (version && THUMBNAIL_VERSION_PATTERN.test(version)) { @@ -32,5 +30,8 @@ export async function GET(req: NextRequest) { }); } - return generateVideoOgImage(Video.VideoId.make(videoId)); + return generateVideoOgImage( + Video.VideoId.make(videoId), + canonical.get("v"), + ); } From 3237bedd72a3cba1003a43961824e291d82b55f2 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 17 Nov 2026 01:57:52 +0000 Subject: [PATCH 12/13] chore(web): drop comments that restate the code --- apps/web/app/api/video/og/route.tsx | 5 +---- .../app/s/[videoId]/_components/ShareLinkDialog.tsx | 1 - .../app/s/[videoId]/_components/VideoPreviewGif.tsx | 4 ---- .../call-to-action/CallToActionDialog.tsx | 1 - apps/web/lib/custom-thumbnail.ts | 4 ---- apps/web/lib/embed-code.ts | 1 - apps/web/lib/embed-options.ts | 12 ++---------- apps/web/lib/player-brand.ts | 5 ----- apps/web/lib/share-playback.ts | 4 ---- apps/web/lib/share-video-metadata.ts | 4 ---- packages/web-backend/src/Storage/custom-thumbnail.ts | 4 ---- 11 files changed, 3 insertions(+), 42 deletions(-) diff --git a/apps/web/app/api/video/og/route.tsx b/apps/web/app/api/video/og/route.tsx index 1afb4b7c942..015f81371ad 100644 --- a/apps/web/app/api/video/og/route.tsx +++ b/apps/web/app/api/video/og/route.tsx @@ -30,8 +30,5 @@ export async function GET(req: NextRequest) { }); } - return generateVideoOgImage( - Video.VideoId.make(videoId), - canonical.get("v"), - ); + return generateVideoOgImage(Video.VideoId.make(videoId), canonical.get("v")); } diff --git a/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx b/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx index 472ab75e48b..3b074467d39 100644 --- a/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx +++ b/apps/web/app/s/[videoId]/_components/ShareLinkDialog.tsx @@ -106,7 +106,6 @@ export const ShareLinkDialog = ({ isPublic: boolean; canManageAccess?: boolean; onManageAccess?: () => void; - /** Logo hiding follows the owner's plan, like the share page logo. */ ownerIsPro?: boolean; }) => { const { webUrl } = usePublicEnv(); diff --git a/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx b/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx index b001e21276d..a6e5c968990 100644 --- a/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx +++ b/apps/web/app/s/[videoId]/_components/VideoPreviewGif.tsx @@ -67,10 +67,6 @@ function PreviewGifImage({ ); } -/** - * The owner's custom thumbnail, shown in place of the animated preview until - * the first play. Rendered from the server-signed URL so it is in the HTML. - */ export function VideoPoster({ src, visible, diff --git a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx index b8c5fdfd018..bb376f4072e 100644 --- a/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx +++ b/apps/web/app/s/[videoId]/_components/call-to-action/CallToActionDialog.tsx @@ -126,7 +126,6 @@ export function CallToActionDialog({ callToAction: ShareCallToAction | null; onSaved?: (callToAction: ShareCallToAction | null) => void; onUpgradeRequest: () => void; - /** The organization's brand colour, offered first and used for new CTAs. */ brandColor?: string | null; }) { const isWorkspace = target.kind === "workspace"; diff --git a/apps/web/lib/custom-thumbnail.ts b/apps/web/lib/custom-thumbnail.ts index 61e404634f4..cef951f7976 100644 --- a/apps/web/lib/custom-thumbnail.ts +++ b/apps/web/lib/custom-thumbnail.ts @@ -6,7 +6,6 @@ export const CUSTOM_THUMBNAIL_MAX_DIMENSION = 1920; */ export const CUSTOM_THUMBNAIL_MAX_BYTES = 900 * 1024; -/** What people can pick before it is resized in the browser. */ export const CUSTOM_THUMBNAIL_MAX_SOURCE_BYTES = 20 * 1024 * 1024; export const CUSTOM_THUMBNAIL_ACCEPT = "image/png,image/jpeg,image/webp"; @@ -38,9 +37,6 @@ export function isJpegData(data: Uint8Array): boolean { ); } -/** - * Fits `width` x `height` inside the thumbnail bounds without upscaling. - */ export function fitThumbnailSize(width: number, height: number) { if (!(width > 0) || !(height > 0)) return null; const scale = Math.min( diff --git a/apps/web/lib/embed-code.ts b/apps/web/lib/embed-code.ts index 2a4ed0381b2..5eff204053c 100644 --- a/apps/web/lib/embed-code.ts +++ b/apps/web/lib/embed-code.ts @@ -16,7 +16,6 @@ export const buildEmbedCode = ({ videoId: string; /** Seconds to start playback at, if the sharer picked a moment. */ startTime?: number | null; - /** Toggles from the embed tab. Defaults leave the snippet as it was. */ options?: Partial>; }): string => { const query = buildEmbedQuery({ ...options, startTime }); diff --git a/apps/web/lib/embed-options.ts b/apps/web/lib/embed-options.ts index b95065e536e..df9840de8cb 100644 --- a/apps/web/lib/embed-options.ts +++ b/apps/web/lib/embed-options.ts @@ -4,7 +4,6 @@ export type EmbedOptions = { showBranding: boolean; autoplay: boolean; muted: boolean; - /** Seconds to open at. */ startTime: number | null; }; @@ -39,11 +38,8 @@ const parseStartTime = (value: string | undefined) => { return Number.isFinite(parsed) && parsed > 0 ? parsed : null; }; -/** - * Reads the embed URL. Every option defaults to how embeds have always - * looked, so only an explicit `false` hides something and only an explicit - * `true` turns autoplay or muting on. - */ +// Only an explicit `false` hides something and only an explicit `true` turns +// autoplay or muting on, so embeds without params keep how they always looked. export function parseEmbedOptions(params: SearchParamsInput): EmbedOptions { return { showTitle: !isOff(readParam(params, "title")), @@ -55,10 +51,6 @@ export function parseEmbedOptions(params: SearchParamsInput): EmbedOptions { }; } -/** - * The query string for an embed URL, in a fixed order, omitting every option - * left at its default. Defaults produce an empty string. - */ export function buildEmbedQuery(options: Partial): string { const params = new URLSearchParams(); const startTime = options.startTime; diff --git a/apps/web/lib/player-brand.ts b/apps/web/lib/player-brand.ts index 77b932b395d..f2b56a7edab 100644 --- a/apps/web/lib/player-brand.ts +++ b/apps/web/lib/player-brand.ts @@ -15,7 +15,6 @@ export type PlayerBrand = { color: string; foreground: typeof PLAYER_BRAND_INK | typeof PLAYER_BRAND_WHITE; hover: string; - /** Null when the colour is too dark to read on the player's dark controls. */ accent: string | null; }; @@ -134,10 +133,6 @@ export function playerColorFromOrganizationMetadata( return normalizeHexColor(metadata.branding.playerColor); } -/** - * Brand colour is a Pro feature, gated on the video owner's plan the same way - * the share page logo is. - */ export function getPlayerBrand({ ownerIsPro, organizationMetadata, diff --git a/apps/web/lib/share-playback.ts b/apps/web/lib/share-playback.ts index 61e613c13b1..4a704c54844 100644 --- a/apps/web/lib/share-playback.ts +++ b/apps/web/lib/share-playback.ts @@ -42,10 +42,6 @@ export const getSharePlaybackSource = ( .pipe(runPromise) .catch(() => null); -/** - * Signs the owner's custom thumbnail, if there is one. Callers only reach for - * this when the video's metadata names one, so other pages pay nothing. - */ export const getCustomThumbnailUrl = ( video: SharePlaybackVideo, key: string, diff --git a/apps/web/lib/share-video-metadata.ts b/apps/web/lib/share-video-metadata.ts index bf0bc7a7a4d..b782e22d10e 100644 --- a/apps/web/lib/share-video-metadata.ts +++ b/apps/web/lib/share-video-metadata.ts @@ -25,10 +25,6 @@ export type ShareVideoMetadataInput = { */ canonicalWebUrl?: string; advertiseIframelyPlayer?: boolean; - /** - * Set when the owner picked a thumbnail. Link previews then show it instead - * of the animated preview, under a URL that changes with every new pick. - */ thumbnailVersion?: string | null; }; diff --git a/packages/web-backend/src/Storage/custom-thumbnail.ts b/packages/web-backend/src/Storage/custom-thumbnail.ts index 1fd30924366..c526a70f88f 100644 --- a/packages/web-backend/src/Storage/custom-thumbnail.ts +++ b/packages/web-backend/src/Storage/custom-thumbnail.ts @@ -62,10 +62,6 @@ export function getCustomThumbnailKey(video: CustomThumbnailVideo) { }); } -/** - * Changes whenever the custom thumbnail does, so URLs that embed it (link - * preview images) miss every cache the moment the owner picks a new one. - */ export function getCustomThumbnailVersion(metadata: unknown) { const custom = getCustomThumbnailMetadata(metadata); return custom ? custom.file.slice("custom-".length, -".jpg".length) : null; From abeb44d728660dbddfeea9878cc8f581e2e13703 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:13:00 +0000 Subject: [PATCH 13/13] fix(web): use American spelling in brand color settings --- .../organization/shareable-link-icon.ts | 2 +- .../components/ShareableLinkBrandColor.tsx | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/web/actions/organization/shareable-link-icon.ts b/apps/web/actions/organization/shareable-link-icon.ts index ee6c273fab2..ccaff5052a6 100644 --- a/apps/web/actions/organization/shareable-link-icon.ts +++ b/apps/web/actions/organization/shareable-link-icon.ts @@ -213,7 +213,7 @@ export async function updateShareableLinkBrandColor({ }) { const playerColor = color === null ? null : normalizeHexColor(color); if (color !== null && !playerColor) { - throw new Error("Enter a hex colour like #1F6FEB"); + throw new Error("Enter a hex color like #1F6FEB"); } const organization = await getManageableProOrganization(organizationId); diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx index 1c8888d1650..e01754600c5 100644 --- a/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx +++ b/apps/web/app/(org)/dashboard/settings/organization/components/ShareableLinkBrandColor.tsx @@ -64,13 +64,13 @@ export const ShareableLinkBrandColor = () => { }, onSuccess: (result) => { toast.success( - result.color ? "Brand colour saved" : "Share pages use Cap blue again", + result.color ? "Brand color saved" : "Share pages use Cap blue again", ); router.refresh(); }, onError: (error) => { toast.error( - error instanceof Error ? error.message : "Couldn't save brand colour", + error instanceof Error ? error.message : "Couldn't save brand color", ); }, }); @@ -93,14 +93,14 @@ export const ShareableLinkBrandColor = () => { return ( <> } - description="Colours the play button, progress bar and focus rings on your share pages and embeds." + description="Colors the play button, progress bar and focus rings on your share pages and embeds." >
- Brand colour + Brand color { {palette.map((color) => ( { )} style={customSelected ? { background: draft } : undefined} > - Custom colour + Custom color { className="min-h-[2.5rem] text-[13px] leading-5 text-gray-10" > {!hexValid - ? "Use a six digit hex colour, like #1F6FEB." + ? "Use a six digit hex color, like #1F6FEB." : brand && !brand.accent - ? "This colour is too dark to see on video, so the progress bar and focus rings stay white. The play button uses it." + ? "This color is too dark to see on video, so the progress bar and focus rings stay white. The play button uses it." : brand - ? `The play icon is ${brand.foreground === "#FFFFFF" ? "white" : "dark"} on this colour so it stays readable.` + ? `The play icon is ${brand.foreground === "#FFFFFF" ? "white" : "dark"} on this color so it stays readable.` : "Share pages and embeds use Cap blue."}

@@ -268,7 +268,7 @@ function Swatch({ >