Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
ensure more limits don't show when self hosting (#1312)
Brendan Allan8ea26ecde684
diff --git a/apps/web/actions/videos/get-status.ts b/apps/web/actions/videos/get-status.tsindex 93d2daacd..0124d1190 100644--- a/apps/web/actions/videos/get-status.ts+++ b/apps/web/actions/videos/get-status.ts@@ -3,6 +3,7 @@import { db } from "@cap/database";import { users, videos } from "@cap/database/schema";import type { VideoMetadata } from "@cap/database/types";+import { serverEnv } from "@cap/env";import { provideOptionalAuth, VideosPolicy } from "@cap/web-backend";import { Policy, type Video } from "@cap/web-domain";import { eq } from "drizzle-orm";@@ -45,7 +46,7 @@ export async function getVideoStatus(const metadata: VideoMetadata = (video.metadata as VideoMetadata) || {};- if (!video.transcriptionStatus) {+ if (!video.transcriptionStatus && serverEnv().DEEPGRAM_API_KEY) {console.log(`[Get Status] Transcription not started for video ${videoId}, triggering transcription`,);diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsxindex 3d0e4e71d..83f93d56a 100644--- a/apps/web/app/s/[videoId]/Share.tsx+++ b/apps/web/app/s/[videoId]/Share.tsx@@ -22,6 +22,7 @@ import { ShareVideo } from "./_components/ShareVideo";import { Sidebar } from "./_components/Sidebar";import SummaryChapters from "./_components/SummaryChapters";import { Toolbar } from "./_components/Toolbar";+import type { VideoData } from "./types";type CommentWithAuthor = typeof commentsSchema.$inferSelect & {authorName: string | null;@@ -34,16 +35,8 @@ export type CommentType = typeof commentsSchema.$inferSelect & {sending?: boolean;};-type VideoWithOrganizationInfo = typeof videos.$inferSelect & {- organizationMembers?: string[];- organizationId?: string;- sharedOrganizations?: { id: string; name: string }[];- hasPassword?: boolean;- orgSettings?: OrganizationSettings | null;-};-interface ShareProps {- data: VideoWithOrganizationInfo;+ data: VideoData;comments: MaybePromise<CommentWithAuthor[]>;views: MaybePromise<number>;customDomain: string | null;diff --git a/apps/web/app/s/[videoId]/_components/ImageViewer.tsx b/apps/web/app/s/[videoId]/_components/ImageViewer.tsxdeleted file mode 100644index d4d6ad8ca..000000000--- a/apps/web/app/s/[videoId]/_components/ImageViewer.tsx+++ /dev/null@@ -1,112 +0,0 @@-"use client";--import type { userSelectProps } from "@cap/database/auth/session";-import type { comments as commentsSchema, videos } from "@cap/database/schema";-import { LogoSpinner } from "@cap/ui";-import { MessageSquare } from "lucide-react";-import React, { useEffect, useState } from "react";-import { Tooltip } from "react-tooltip";-import { ShareHeader } from "./ShareHeader";-import { Toolbar } from "./Toolbar";--// million-ignore-export const ImageViewer = ({- data,- comments,- imageSrc,-}: {- data: typeof videos.$inferSelect;- comments: (typeof commentsSchema.$inferSelect)[];- imageSrc: string;-}) => {- const [overlayVisible, setOverlayVisible] = useState(false);- const [imageLoaded, setImageLoaded] = useState(false);-- useEffect(() => {- const img = new Image();- img.src = imageSrc;- img.onload = () => setImageLoaded(true);- }, [imageSrc]);-- return (- <div className="wrapper py-8">- <div className="space-y-6">- <ShareHeader data={data} />- <div- className="relative flex h-full w-full overflow-hidden shadow-lg rounded-lg group"- id="player"- onMouseEnter={() => setOverlayVisible(true)}- onMouseLeave={() => setOverlayVisible(false)}- >- <div- className="relative block w-full h-full rounded-lg bg-black"- style={{ paddingBottom: "min(806px, 56.25%)" }}- >- {!imageLoaded && (- <div className="absolute inset-0 flex items-center justify-center">- <LogoSpinner className="w-8 md:w-12 h-auto animate-spin" />- </div>- )}- <img- src={imageSrc}- alt="Image"- className={`absolute top-0 left-0 rounded-lg w-full h-full object-contain transition-opacity duration-300 ${- imageLoaded ? "opacity-100" : "opacity-0"- }`}- onLoad={() => setImageLoaded(true)}- />- {comments.length > 0 && imageLoaded && (- <div- className={`absolute inset-0 bg-black transition-opacity duration-300 ${- overlayVisible ? "opacity-50" : "opacity-0"- }`}- ></div>- )}- {imageLoaded && (- <div- className={`absolute bottom-0 left-0 w-full transition-opacity duration-300 ${- overlayVisible ? "opacity-100" : "opacity-0"- }`}- >- <div className="flex justify-center items-center space-x-2 p-4">- {comments.map((comment) => (- <React.Fragment key={comment.id}>- <div- className="text-[16px] hover:scale-125 transition-all cursor-pointer"- data-tooltip-id={comment.id}- >- <span>- {comment.type === "text" ? (- <MessageSquare- fill="#646464"- className="w-auto h-[22px] text-white"- />- ) : (- comment.content- )}- </span>- </div>- <Tooltip- id={comment.id}- content={- comment.type === "text"- ? `User: ${comment.content}`- : comment.authorId === "anonymous"- ? "Anonymous"- : "User"- }- />- </React.Fragment>- ))}- </div>- </div>- )}- </div>- </div>- <div className="flex justify-center">- <Toolbar data={data} />- </div>- </div>- </div>- );-};diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsxindex 7666184f5..f3992bd2e 100644--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx@@ -1,11 +1,9 @@"use client";-import type { userSelectProps } from "@cap/database/auth/session";import type { videos } from "@cap/database/schema";import { buildEnv, NODE_ENV } from "@cap/env";import { Button } from "@cap/ui";-import { userIsPro } from "@cap/utils";-import type { ImageUpload } from "@cap/web-domain";+import { type ImageUpload, User } from "@cap/web-domain";import { faChevronDown, faLock } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { Check, Copy, Globe2 } from "lucide-react";@@ -21,6 +19,7 @@ import { useCurrentUser } from "@/app/Layout/AuthContext";import { SignedImageUrl } from "@/components/SignedImageUrl";import { UpgradeModal } from "@/components/UpgradeModal";import { usePublicEnv } from "@/utils/public-env";+import type { VideoData } from "../types";export const ShareHeader = ({data,@@ -30,11 +29,7 @@ export const ShareHeader = ({sharedSpaces = [],spacesData = null,}: {- data: typeof videos.$inferSelect & {- ownerName?: string | null;- ownerImage?: ImageUpload.ImageUrl | null;- ownerIsPro?: boolean;- };+ data: VideoData;customDomain?: string | null;domainVerified?: boolean;sharedOrganizations?: { id: string; name: string }[];@@ -65,7 +60,7 @@ export const ShareHeader = ({const contextSharedSpaces = contextData?.sharedSpaces || null;const effectiveSharedSpaces = contextSharedSpaces || sharedSpaces;- const isOwner = user && user.id === data.ownerId;+ const isOwner = user && user.id === data.owner.id;const { webUrl } = usePublicEnv();@@ -132,8 +127,6 @@ export const ShareHeader = ({}};- const isVideoOwnerPro: boolean = data.ownerIsPro ?? false;-const handleSharingUpdated = () => {refresh();};@@ -182,9 +175,11 @@ export const ShareHeader = ({}};+ const userIsOwnerAndNotPro = user?.id === data.owner.id && !data.owner.isPro;+return (<>- {isOwner && !isVideoOwnerPro && (+ {userIsOwnerAndNotPro && (<div className="flex sticky flex-col sm:flex-row inset-x-0 top-0 z-10 gap-4 justify-center items-center px-3 py-2 mx-auto w-[calc(100%-20px)] max-w-fit rounded-b-xl border bg-gray-4 border-gray-6"><p className="text-center text-gray-12">Shareable links are limited to 5 mins on the free plan.@@ -238,16 +233,16 @@ export const ShareHeader = ({</div><div className="flex gap-7 items-center"><div className="flex gap-2 items-center">- {data.ownerName && (+ {data.name && (<SignedImageUrl- name={data.ownerName}- image={data.ownerImage}+ name={data.name}+ image={data.owner.image}className="size-8"letterClass="text-base"/>)}<div className="flex flex-col text-left">- <p className="text-sm text-gray-12">{data.ownerName}</p>+ <p className="text-sm text-gray-12">{data.name}</p><p className="text-xs text-gray-10">{moment(data.createdAt).fromNow()}</p>@@ -285,7 +280,7 @@ export const ShareHeader = ({)}</Button></div>- {!isVideoOwnerPro && (+ {userIsOwnerAndNotPro && (<buttontype="button"className="flex items-center mt-2 mb-3 text-sm text-gray-400 duration-200 cursor-pointer hover:text-blue-500"diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex 49fcb681f..a7443a404 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -13,6 +13,7 @@ import {} from "react";import type { OrganizationSettings } from "@/app/(org)/dashboard/dashboard-data";import { UpgradeModal } from "@/components/UpgradeModal";+import type { VideoData } from "../types";import { CapVideoPlayer } from "./CapVideoPlayer";import { HLSVideoPlayer } from "./HLSVideoPlayer";import {@@ -36,10 +37,8 @@ type CommentWithAuthor = typeof commentsSchema.$inferSelect & {export const ShareVideo = forwardRef<HTMLVideoElement,{- data: typeof videos.$inferSelect & {- ownerIsPro?: boolean;+ data: VideoData & {hasActiveUpload?: boolean;- orgSettings?: OrganizationSettings | null;};comments: MaybePromise<CommentWithAuthor[]>;chapters?: { title: string; start: number }[];@@ -166,7 +165,7 @@ export const ShareVideo = forwardRef<let enableCrossOrigin = false;if (data.source.type === "desktopMP4") {- videoSrc = `/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=mp4`;+ videoSrc = `/api/playlist?userId=${data.owner.id}&videoId=${data.id}&videoType=mp4`;// Start with CORS enabled for desktopMP4, but CapVideoPlayer will dynamically disable if neededenableCrossOrigin = true;} else if (@@ -174,11 +173,11 @@ export const ShareVideo = forwardRef<((data.skipProcessing === true || data.jobStatus !== "COMPLETE") &&data.source.type === "MediaConvert")) {- videoSrc = `/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=master`;+ videoSrc = `/api/playlist?userId=${data.owner.id}&videoId=${data.id}&videoType=master`;} else if (data.source.type === "MediaConvert") {- videoSrc = `/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=video`;+ videoSrc = `/api/playlist?userId=${data.owner.id}&videoId=${data.id}&videoType=video`;} else {- videoSrc = `/api/playlist?userId=${data.ownerId}&videoId=${data.id}&videoType=video`;+ videoSrc = `/api/playlist?userId=${data.owner.id}&videoId=${data.id}&videoType=video`;}return (@@ -221,7 +220,7 @@ export const ShareVideo = forwardRef<)}</div>- {!data.ownerIsPro && (+ {!data.owner.isPro && (<div className="absolute top-4 left-4 z-30"><divclassName="block cursor-pointer"diff --git a/apps/web/app/s/[videoId]/_components/Sidebar.tsx b/apps/web/app/s/[videoId]/_components/Sidebar.tsxindex 409ad205e..9625f33d5 100644--- a/apps/web/app/s/[videoId]/_components/Sidebar.tsx+++ b/apps/web/app/s/[videoId]/_components/Sidebar.tsx@@ -7,6 +7,7 @@ import { AnimatePresence, motion } from "framer-motion";import { forwardRef, Suspense, useState } from "react";import type { OrganizationSettings } from "@/app/(org)/dashboard/dashboard-data";import { useCurrentUser } from "@/app/Layout/AuthContext";+import type { VideoData } from "../types";import { Activity } from "./tabs/Activity";import { Settings } from "./tabs/Settings";import { Summary } from "./tabs/Summary";@@ -19,14 +20,8 @@ type CommentType = typeof commentsSchema.$inferSelect & {authorImage?: ImageUpload.ImageUrl | null;};-type VideoWithOrganizationInfo = typeof videos.$inferSelect & {- organizationMembers?: string[];- organizationId?: string;- orgSettings?: OrganizationSettings | null;-};-interface SidebarProps {- data: VideoWithOrganizationInfo;+ data: VideoData;commentsData: CommentType[];optimisticComments: CommentType[];handleCommentSuccess: (comment: CommentType) => void;@@ -91,10 +86,9 @@ export const Sidebar = forwardRef<{ scrollToBottom: () => void }, SidebarProps>() => {const user = useCurrentUser();- const isOwnerOrMember: boolean = Boolean(- user?.id === data.ownerId ||- (data.organizationId &&- data.organizationMembers?.includes(user?.id ?? "")),+ const isOwnerOrMember = Boolean(+ user?.id === data.owner.id ||+ (user && data.organizationMembers?.includes(user.id)),);const defaultTab = !(@@ -182,7 +176,7 @@ export const Sidebar = forwardRef<{ scrollToBottom: () => void }, SidebarProps>(/>);case "transcript":- return <Transcript data={data} onSeek={onSeek} user={user} />;+ return <Transcript data={data} onSeek={onSeek} />;case "settings":return <Settings />;default:diff --git a/apps/web/app/s/[videoId]/_components/Toolbar.tsx b/apps/web/app/s/[videoId]/_components/Toolbar.tsxindex 05b7080a7..8f333c56f 100644--- a/apps/web/app/s/[videoId]/_components/Toolbar.tsx+++ b/apps/web/app/s/[videoId]/_components/Toolbar.tsx@@ -1,22 +1,18 @@-import type { userSelectProps } from "@cap/database/auth/session";-import type { videos } from "@cap/database/schema";import { Button } from "@cap/ui";-import { Comment, User } from "@cap/web-domain";+import { Comment } from "@cap/web-domain";import { AnimatePresence, motion } from "motion/react";import { startTransition, useEffect, useState } from "react";import { newComment } from "@/actions/videos/new-comment";-import type { OrganizationSettings } from "@/app/(org)/dashboard/dashboard-data";import { useCurrentUser } from "@/app/Layout/AuthContext";import type { CommentType } from "../Share";+import type { VideoData } from "../types";import { AuthOverlay } from "./AuthOverlay";const MotionButton = motion.create(Button);// million-ignoreinterface ToolbarProps {- data: typeof videos.$inferSelect & {- orgSettings?: OrganizationSettings | null;- };+ data: VideoData;onOptimisticComment?: (comment: CommentType) => void;onCommentSuccess?: (comment: CommentType) => void;disableReactions?: boolean;diff --git a/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx b/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsxindex 64cc7ae3d..5d5d0d721 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx@@ -7,9 +7,11 @@ import { useInvalidateTranscript, useTranscript } from "hooks/use-transcript";import { Check, Copy, Download, Edit3, MessageSquare, X } from "lucide-react";import { useEffect, useState } from "react";import { editTranscriptEntry } from "@/actions/videos/edit-transcript";+import { useCurrentUser } from "@/app/Layout/AuthContext";+import type { VideoData } from "../../types";interface TranscriptProps {- data: typeof videos.$inferSelect;+ data: VideoData;onSeek?: (time: number) => void;user?: { id: string } | null;}@@ -117,11 +119,8 @@ const parseVTT = (vttContent: string): TranscriptEntry[] => {return sortedEntries;};-export const Transcript: React.FC<TranscriptProps> = ({- data,- user,- onSeek,-}) => {+export const Transcript: React.FC<TranscriptProps> = ({ data, onSeek }) => {+ const user = useCurrentUser();const [transcriptData, setTranscriptData] = useState<TranscriptEntry[]>([]);const [isLoading, setIsLoading] = useState(true);const [selectedEntry, setSelectedEntry] = useState<number | null>(null);@@ -379,7 +378,7 @@ export const Transcript: React.FC<TranscriptProps> = ({}, 2000);};- const canEdit = user?.id === data.ownerId;+ const canEdit = user?.id === data.owner.id;if (isLoading) {return (diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex 13dcfce30..2b28b08eb 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -14,6 +14,7 @@ import {import type { VideoMetadata } from "@cap/database/types";import { buildEnv } from "@cap/env";import { Logo } from "@cap/ui";+import { userIsPro } from "@cap/utils";import {Database,ImageUploads,@@ -276,7 +277,6 @@ export default async function ShareVideoPage(props: PageProps<"/s/[videoId]">) {.select({id: videos.id,name: videos.name,- ownerId: videos.ownerId,ownerName: users.name,ownerImageUrlOrKey: users.image,orgId: videos.orgId,@@ -306,17 +306,14 @@ export default async function ShareVideoPage(props: PageProps<"/s/[videoId]">) {organizationId: sharedVideos.organizationId,},orgSettings: organizations.settings,- ownerIsPro:- sql`${users.stripeSubscriptionStatus} IN ('active','trialing','complete','paid') OR ${users.thirdPartyStripeSubscriptionId} IS NOT NULL`.mapWith(- Boolean,- ),hasActiveUpload: sql`${videoUploads.videoId} IS NOT NULL`.mapWith(Boolean,),+ owner: users,}).from(videos).leftJoin(sharedVideos, eq(videos.id, sharedVideos.videoId))- .leftJoin(users, eq(videos.ownerId, users.id))+ .innerJoin(users, eq(videos.ownerId, users.id)).leftJoin(videoUploads, eq(videos.id, videoUploads.videoId)).leftJoin(organizations, eq(videos.orgId, organizations.id)).where(eq(videos.id, videoId)),@@ -367,8 +364,9 @@ async function AuthorizedContent({}: {video: Omit<InferSelectModel<typeof videos>,- "folderId" | "password" | "settings"+ "folderId" | "password" | "settings" | "ownerId"> & {+ owner: InferSelectModel<typeof users>;sharedOrganization: { organizationId: Organisation.OrganisationId } | null;hasPassword: boolean;ownerIsPro?: boolean;@@ -383,7 +381,7 @@ async function AuthorizedContent({const user = await getCurrentUser();const videoId = video.id;- if (user && video && user.id !== video.ownerId) {+ if (user && video && user.id !== video.owner.id) {try {await createNotification({type: "view",@@ -425,7 +423,7 @@ async function AuthorizedContent({stripeSubscriptionStatus: users.stripeSubscriptionStatus,}).from(users)- .where(eq(users.id, video.ownerId))+ .where(eq(users.id, video.owner.id)).limit(1);if (videoOwnerQuery.length > 0 && videoOwnerQuery[0]) {@@ -470,7 +468,7 @@ async function AuthorizedContent({video.transcriptionStatus !== "PROCESSING") {console.log("[ShareVideoPage] Starting transcription for video:", videoId);- await transcribeVideo(videoId, video.ownerId, aiGenerationEnabled);+ await transcribeVideo(videoId, video.owner.id, aiGenerationEnabled);const updatedVideoQuery = await db().select({@@ -548,7 +546,7 @@ async function AuthorizedContent({aiGenerationEnabled) {try {- generateAiMetadata(videoId, video.ownerId).catch((error) => {+ generateAiMetadata(videoId, video.owner.id).catch((error) => {console.error(`[ShareVideoPage] Error generating AI metadata for video ${videoId}:`,error,@@ -586,7 +584,7 @@ async function AuthorizedContent({org &&org.customDomain &&org.domainVerified !== null &&- user.id === video.ownerId+ user.id === video.owner.id) {return { customDomain: org.customDomain, domainVerified: true };}@@ -725,13 +723,19 @@ async function AuthorizedContent({return {...video,- ownerImage: video.ownerImageUrlOrKey- ? yield* imageUploads.resolveImageUrl(video.ownerImageUrlOrKey)- : null,- organizationMembers: membersList.map((member) => member.userId),- organizationId: video.sharedOrganization?.organizationId ?? undefined,+ owner: {+ id: video.owner.id,+ name: video.owner.name,+ isPro: userIsPro(video.owner),+ image: video.ownerImageUrlOrKey+ ? yield* imageUploads.resolveImageUrl(video.ownerImageUrlOrKey)+ : null,+ },+ organization: {+ organizationMembers: membersList.map((member) => member.userId),+ organizationId: video.sharedOrganization?.organizationId ?? undefined,+ },sharedOrganizations: sharedOrganizations,- ownerIsPro: video.ownerIsPro ?? false,password: null,folderId: null,orgSettings: video.orgSettings || null,diff --git a/apps/web/app/s/[videoId]/types.ts b/apps/web/app/s/[videoId]/types.tsnew file mode 100644index 000000000..6bd2536f8--- /dev/null+++ b/apps/web/app/s/[videoId]/types.ts@@ -0,0 +1,19 @@+import type { videos } from "@cap/database/schema";+import type { ImageUpload, Organisation, User } from "@cap/web-domain";+import type { OrganizationSettings } from "@/app/(org)/dashboard/dashboard-data";++export type VideoData = Omit<typeof videos.$inferSelect, "ownerId"> & {+ owner: VideoOwner;+ organizationMembers?: User.UserId[];+ organizationId?: Organisation.OrganisationId;+ sharedOrganizations?: { id: string; name: string }[];+ hasPassword?: boolean;+ orgSettings?: OrganizationSettings | null;+};++export type VideoOwner = {+ id: User.UserId;+ isPro: boolean;+ name?: string | null;+ image?: ImageUpload.ImageUrl | null;+};diff --git a/packages/web-backend/src/Auth.ts b/packages/web-backend/src/Auth.tsindex fed3808c2..08cebb6cf 100644--- a/packages/web-backend/src/Auth.ts+++ b/packages/web-backend/src/Auth.ts@@ -105,9 +105,6 @@ export const provideOptionalAuth = <A, E, R>(Effect.gen(function* () {const user = yield* getCurrentUser;- if (Option.isSome(user))- yield* Effect.log(`Providing auth for user ${user.value.id}`);-return yield* user.pipe(Option.match({onNone: () => app,