Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): honor effective viewer settings on share and embed pages

Richie McIlroy68ce15b5ba4f
diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx
index 395cb7098..45f2e1762 100644
--- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx
+++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx
@@ -4,6 +4,7 @@ import type { userSelectProps } from "@cap/database/auth/session";
import type { comments as commentsSchema, videos } from "@cap/database/schema";
import { NODE_ENV } from "@cap/env";
import { Avatar, Logo } from "@cap/ui";
+import type { ViewerSettings } from "@cap/web-backend";
import { AnimatePresence, motion } from "framer-motion";
import { useTranscript } from "hooks/use-transcript";
import {
@@ -56,6 +57,7 @@ export const EmbedVideo = forwardRef<
chapters?: { title: string; start: number }[];
ownerName?: string | null;
autoplay?: boolean;
+ viewerSettings?: ViewerSettings | null;
showPlaybackStatusBadge?: boolean;
}
>(
@@ -67,6 +69,7 @@ export const EmbedVideo = forwardRef<
chapters = [],
ownerName,
autoplay: _autoplay = false,
+ viewerSettings,
showPlaybackStatusBadge = false,
},
ref,
@@ -86,10 +89,12 @@ export const EmbedVideo = forwardRef<
);
const [subtitleUrl, setSubtitleUrl] = useState<string | null>(null);
const [chaptersUrl, setChaptersUrl] = useState<string | null>(null);
+ const captionsDisabled = viewerSettings?.disableCaptions ?? false;
+ const chaptersDisabled = viewerSettings?.disableChapters ?? false;
const { data: transcriptContent, error: transcriptError } = useTranscript(
data.id,
- data.transcriptionStatus,
+ captionsDisabled ? null : data.transcriptionStatus,
);
useEffect(() => {
@@ -106,6 +111,7 @@ export const EmbedVideo = forwardRef<
useEffect(() => {
if (
+ !captionsDisabled &&
data.transcriptionStatus === "COMPLETE" &&
transcriptData &&
transcriptData.length > 0
@@ -125,10 +131,10 @@ export const EmbedVideo = forwardRef<
if (prev) URL.revokeObjectURL(prev);
return null;
});
- }, [data.transcriptionStatus, transcriptData]);
+ }, [captionsDisabled, data.transcriptionStatus, transcriptData]);
useEffect(() => {
- if (chapters?.length > 0) {
+ if (!chaptersDisabled && chapters?.length > 0) {
const vttContent = formatChaptersAsVTT(chapters);
const blob = new Blob([vttContent], { type: "text/vtt" });
const newUrl = URL.createObjectURL(blob);
@@ -144,7 +150,7 @@ export const EmbedVideo = forwardRef<
if (prev) URL.revokeObjectURL(prev);
return null;
});
- }, [chapters]);
+ }, [chapters, chaptersDisabled]);
const isMp4Source =
data.source.type === "desktopMP4" || data.source.type === "webMP4";
@@ -237,8 +243,9 @@ export const EmbedVideo = forwardRef<
rawFallbackSrc={rawFallbackSrc}
duration={data.duration}
showPlaybackStatusBadge={showPlaybackStatusBadge}
- chaptersSrc={chaptersUrl || ""}
- captionsSrc={subtitleUrl || ""}
+ disableCaptions={captionsDisabled}
+ chaptersSrc={chaptersDisabled ? "" : chaptersUrl || ""}
+ captionsSrc={captionsDisabled ? "" : subtitleUrl || ""}
videoRef={videoRef}
enableCrossOrigin={enableCrossOrigin}
hasActiveUpload={data.hasActiveUpload}
@@ -249,8 +256,9 @@ export const EmbedVideo = forwardRef<
mediaPlayerClassName="w-full h-full"
videoSrc={videoSrc}
duration={data.duration}
- chaptersSrc={chaptersUrl || ""}
- captionsSrc={subtitleUrl || ""}
+ disableCaptions={captionsDisabled}
+ chaptersSrc={chaptersDisabled ? "" : chaptersUrl || ""}
+ captionsSrc={captionsDisabled ? "" : subtitleUrl || ""}
videoRef={videoRef}
hasActiveUpload={data.hasActiveUpload}
isLiveSegments={isSegmentsSource}
diff --git a/apps/web/app/embed/[videoId]/page.tsx b/apps/web/app/embed/[videoId]/page.tsx
index 7b88dc53b..5a8ca764f 100644
--- a/apps/web/app/embed/[videoId]/page.tsx
+++ b/apps/web/app/embed/[videoId]/page.tsx
@@ -4,13 +4,20 @@ import {
comments,
organizations,
sharedVideos,
+ spaces,
+ spaceVideos,
users,
videos,
videoUploads,
} from "@cap/database/schema";
import type { VideoMetadata } from "@cap/database/types";
import { buildEnv } from "@cap/env";
-import { provideOptionalAuth, Videos, VideosPolicy } from "@cap/web-backend";
+import {
+ provideOptionalAuth,
+ resolveEffectiveVideoRules,
+ Videos,
+ VideosPolicy,
+} from "@cap/web-backend";
import { type Organisation, Policy, type Video } from "@cap/web-domain";
import { and, eq, isNull, sql } from "drizzle-orm";
import { Effect, Option } from "effect";
@@ -105,6 +112,19 @@ export async function generateMetadata(
);
}
+const renderEmbedPolicyDenied = () =>
+ Effect.succeed(
+ <div className="flex flex-col justify-center items-center min-h-screen text-center text-white bg-black">
+ <h1 className="mb-4 text-2xl font-bold">This video is private</h1>
+ <p className="text-gray-400">
+ If you own this video, please <Link href="/login">sign in</Link> to
+ manage sharing.
+ </p>
+ </div>,
+ );
+
+const renderNoSuchElement = () => Effect.sync(() => notFound());
+
export default async function EmbedVideoPage(
props: PageProps<"/embed/[videoId]">,
) {
@@ -152,6 +172,7 @@ export default async function EmbedVideoPage(
sharedOrganization: {
organizationId: sharedVideos.organizationId,
},
+ orgSettings: organizations.settings,
hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(
Boolean,
),
@@ -171,7 +192,7 @@ export default async function EmbedVideoPage(
Effect.succeed({ needsPassword: true } as const),
),
Effect.map((data) => (
- <div className="min-h-screen bg-black">
+ <div key={videoId} className="min-h-screen bg-black">
<PasswordOverlay isOpen={data.needsPassword} videoId={videoId} />
{!data.needsPassword && (
<EmbedContent video={data.video} autoplay={autoplay} />
@@ -179,17 +200,8 @@ export default async function EmbedVideoPage(
</div>
)),
Effect.catchTags({
- PolicyDenied: () =>
- Effect.succeed(
- <div className="flex flex-col justify-center items-center min-h-screen text-center text-white bg-black">
- <h1 className="mb-4 text-2xl font-bold">This video is private</h1>
- <p className="text-gray-400">
- If you own this video, please <Link href="/login">sign in</Link>{" "}
- to manage sharing.
- </p>
- </div>,
- ),
- NoSuchElementException: () => Effect.sync(() => notFound()),
+ PolicyDenied: renderEmbedPolicyDenied,
+ NoSuchElementException: renderNoSuchElement,
}),
provideOptionalAuth,
EffectRuntime.runPromise,
@@ -203,10 +215,27 @@ async function EmbedContent({
video: Omit<typeof videos.$inferSelect, "password"> & {
sharedOrganization: { organizationId: Organisation.OrganisationId } | null;
hasActiveUpload: boolean | undefined;
+ orgSettings?: (typeof organizations.$inferSelect)["settings"] | null;
};
autoplay: boolean;
}) {
const user = await getCurrentUser();
+ const sharedSpaces = await db()
+ .select({
+ id: spaces.id,
+ name: spaces.name,
+ settings: spaces.settings,
+ hasPassword: sql`${spaces.password} IS NOT NULL`.mapWith(Boolean),
+ })
+ .from(spaceVideos)
+ .innerJoin(spaces, eq(spaceVideos.spaceId, spaces.id))
+ .where(eq(spaceVideos.videoId, video.id));
+
+ const rules = resolveEffectiveVideoRules({
+ videoSettings: video.settings,
+ organizationSettings: video.orgSettings,
+ spaces: sharedSpaces,
+ });
let aiGenerationEnabled = false;
const videoOwnerQuery = await db()
@@ -225,6 +254,7 @@ async function EmbedContent({
}
if (
+ !rules.settings.disableTranscript &&
video.transcriptionStatus !== "COMPLETE" &&
video.transcriptionStatus !== "PROCESSING" &&
video.transcriptionStatus !== "SKIPPED" &&
@@ -286,9 +316,12 @@ async function EmbedContent({
data={video}
user={user}
comments={commentsQuery}
- chapters={initialAiData?.chapters || []}
+ chapters={
+ rules.settings.disableChapters ? [] : initialAiData?.chapters || []
+ }
ownerName={videoOwner[0]?.name || null}
autoplay={autoplay}
+ viewerSettings={rules.settings}
showPlaybackStatusBadge={user?.id === video.ownerId}
/>
);
diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
index ef4dc566c..28a89a538 100644
--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx
@@ -2,6 +2,7 @@
import { buildEnv, NODE_ENV } from "@cap/env";
import { Button } from "@cap/ui";
+import type { ViewerSettingKey } from "@cap/web-backend";
import {
faChartSimple,
faChevronDown,
@@ -42,12 +43,16 @@ export const ShareHeader = ({
name: string;
iconUrl?: string;
organizationId: string;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
}[];
userSpaces?: {
id: string;
name: string;
iconUrl?: string;
organizationId: string;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
}[];
spacesData?: Spaces[] | null;
}) => {
@@ -257,6 +262,7 @@ export const ShareHeader = ({
isPublic={data.public}
spacesData={spacesData}
hasPassword={!!data.hasPassword}
+ inheritedPasswordSources={data.inheritedPasswordSources}
onPasswordUpdated={() => refresh()}
user={user}
onUpgradeRequest={setUpgradeModalOpen}
@@ -276,12 +282,23 @@ export const ShareHeader = ({
/>
) : (
<h1
+ role={isOwner ? "button" : undefined}
+ tabIndex={isOwner ? 0 : undefined}
className="text-xl sm:text-2xl"
onClick={() => {
if (isOwner) {
setIsEditing(true);
}
}}
+ onKeyDown={(event) => {
+ if (
+ isOwner &&
+ (event.key === "Enter" || event.key === " ")
+ ) {
+ event.preventDefault();
+ setIsEditing(true);
+ }
+ }}
>
{title}
</h1>
@@ -312,7 +329,7 @@ export const ShareHeader = ({
<div className="flex space-x-2">
<div>
<div className="flex gap-2 items-center">
- {data.hasPassword && (
+ {(data.hasPassword || data.hasInheritedPassword) && (
<FontAwesomeIcon
className="text-amber-600 size-4"
icon={faLock}
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index bd1d890e6..e150162fb 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -19,6 +19,7 @@ import {
Database,
ImageUploads,
provideOptionalAuth,
+ resolveEffectiveVideoRules,
Videos,
} from "@cap/web-backend";
import { VideosPolicy } from "@cap/web-backend/src/Videos/VideosPolicy";
@@ -61,7 +62,9 @@ async function getSharedSpacesForVideo(videoId: Video.VideoId) {
id: spaces.id,
name: spaces.name,
organizationId: spaces.organizationId,
- iconUrl: organizations.iconUrl,
+ iconUrl: spaces.iconUrl,
+ settings: spaces.settings,
+ hasPassword: sql`${spaces.password} IS NOT NULL`.mapWith(Boolean),
})
.from(spaceVideos)
.innerJoin(spaces, eq(spaceVideos.spaceId, spaces.id))
@@ -85,6 +88,8 @@ async function getSharedSpacesForVideo(videoId: Video.VideoId) {
name: string;
organizationId: string;
iconUrl?: string;
+ settings?: OrganizationSettings | null;
+ hasPassword?: boolean;
}> = [];
// Add space-level sharing
@@ -94,6 +99,8 @@ async function getSharedSpacesForVideo(videoId: Video.VideoId) {
name: space.name,
organizationId: space.organizationId,
iconUrl: space.iconUrl || undefined,
+ settings: space.settings,
+ hasPassword: space.hasPassword,
});
});
@@ -104,6 +111,8 @@ async function getSharedSpacesForVideo(videoId: Video.VideoId) {
name: org.name,
organizationId: org.organizationId,
iconUrl: org.iconUrl || undefined,
+ settings: null,
+ hasPassword: false,
});
});
@@ -445,6 +454,11 @@ async function AuthorizedContent({
// Fetch shared spaces data for this video
const sharedSpaces = await getSharedSpacesForVideo(videoId);
+ const rules = resolveEffectiveVideoRules({
+ videoSettings: video.videoSettings,
+ organizationSettings: video.orgSettings,
+ spaces: sharedSpaces.filter((space) => space.id !== space.organizationId),
+ });
let aiGenerationEnabled = false;
const videoOwnerQuery = await db()
@@ -463,6 +477,7 @@ async function AuthorizedContent({
}
if (
+ !rules.settings.disableTranscript &&
!video.hasActiveUpload &&
video.transcriptionStatus !== "COMPLETE" &&
video.transcriptionStatus !== "PROCESSING" &&
@@ -669,7 +684,10 @@ async function AuthorizedContent({
password: null,
folderId: null,
orgSettings: video.orgSettings || null,
- settings: video.videoSettings || null,
+ settings: rules.settings,
+ hasInheritedPassword: rules.hasInheritedPassword,
+ inheritedPasswordSources: rules.inheritedPasswordSources,
+ inheritedSpaceSettings: rules.inheritedSettings,
};
}).pipe(runPromise);
diff --git a/apps/web/app/s/[videoId]/types.ts b/apps/web/app/s/[videoId]/types.ts
index 6bd2536f8..bd6bf8778 100644
--- a/apps/web/app/s/[videoId]/types.ts
+++ b/apps/web/app/s/[videoId]/types.ts
@@ -1,4 +1,5 @@
import type { videos } from "@cap/database/schema";
+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import type { ImageUpload, Organisation, User } from "@cap/web-domain";
import type { OrganizationSettings } from "@/app/(org)/dashboard/dashboard-data";
@@ -8,6 +9,9 @@ export type VideoData = Omit<typeof videos.$inferSelect, "ownerId"> & {
organizationId?: Organisation.OrganisationId;
sharedOrganizations?: { id: string; name: string }[];
hasPassword?: boolean;
+ hasInheritedPassword?: boolean;
+ inheritedPasswordSources?: SpaceRuleSource[];
+ inheritedSpaceSettings?: Partial<Record<ViewerSettingKey, SpaceRuleSource[]>>;
orgSettings?: OrganizationSettings | null;
};