Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

don't use aws endpoint in video upload (#1279)

Brendan Alland81b2ae873d8
diff --git a/apps/web/actions/organization/update-domain.ts b/apps/web/actions/organization/update-domain.ts
index 20c9d2914..d51adb7ce 100644
--- a/apps/web/actions/organization/update-domain.ts
+++ b/apps/web/actions/organization/update-domain.ts
@@ -3,6 +3,7 @@
import { db } from "@cap/database";
import { getCurrentUser } from "@cap/database/auth/session";
import { organizations } from "@cap/database/schema";
+import { userIsPro } from "@cap/utils";
import type { Organisation } from "@cap/web-domain";
import { eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
@@ -18,10 +19,7 @@ export async function updateDomain(
throw new Error("Unauthorized");
}
- //check user subscription to prevent abuse
- const isSubscribed = user.stripeSubscriptionStatus === "active";
-
- if (!isSubscribed) {
+ if (!userIsPro(user)) {
throw new Error("User is not subscribed");
}
diff --git a/apps/web/actions/video/upload.ts b/apps/web/actions/video/upload.ts
index 71e1c0e4c..4c4b3a748 100644
--- a/apps/web/actions/video/upload.ts
+++ b/apps/web/actions/video/upload.ts
@@ -112,21 +112,10 @@ async function getVideoUploadPresignedUrl({
Option.fromNullable(customBucket?.id),
);
- const presignedPostData = yield* bucket.getPresignedPostUrl(fileKey, {
+ return yield* bucket.getPresignedPostUrl(fileKey, {
Fields,
Expires: 1800,
});
-
- const customEndpoint = serverEnv().CAP_AWS_ENDPOINT;
- if (customEndpoint && !customEndpoint.includes("amazonaws.com")) {
- if (serverEnv().S3_PATH_STYLE) {
- presignedPostData.url = `${customEndpoint}/${bucket.bucketName}`;
- } else {
- presignedPostData.url = customEndpoint;
- }
- }
-
- return presignedPostData;
}).pipe(runPromise);
return { presignedPostData };
diff --git a/apps/web/app/(org)/dashboard/Contexts.tsx b/apps/web/app/(org)/dashboard/Contexts.tsx
index 6caeee6ad..a21098c08 100644
--- a/apps/web/app/(org)/dashboard/Contexts.tsx
+++ b/apps/web/app/(org)/dashboard/Contexts.tsx
@@ -23,7 +23,6 @@ type SharedContext = {
activeSpace: Spaces | null;
user: CurrentUser;
userCapsCount: number | null;
- isSubscribed: boolean;
toggleSidebarCollapsed: () => void;
anyNewNotifications: boolean;
userPreferences: UserPreferences;
@@ -56,7 +55,6 @@ export function DashboardContexts({
activeOrganization,
spacesData,
userCapsCount,
- isSubscribed,
organizationSettings,
userPreferences,
anyNewNotifications,
@@ -69,7 +67,6 @@ export function DashboardContexts({
activeOrganization: SharedContext["activeOrganization"];
spacesData: SharedContext["spacesData"];
userCapsCount: SharedContext["userCapsCount"];
- isSubscribed: SharedContext["isSubscribed"];
organizationSettings: SharedContext["organizationSettings"];
userPreferences: SharedContext["userPreferences"];
anyNewNotifications: boolean;
@@ -172,7 +169,6 @@ export function DashboardContexts({
sharedSpaces,
activeSpace,
user,
- isSubscribed,
toggleSidebarCollapsed,
sidebarCollapsed,
upgradeModalOpen,
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/CapAIDialog.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/CapAIDialog.tsx
index 17f654269..981fef8d0 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/CapAIDialog.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/CapAIDialog.tsx
@@ -15,7 +15,7 @@ import { useDashboardContext, useTheme } from "../../Contexts";
const CapAIDialog = ({ setOpen }: { setOpen: (open: boolean) => void }) => {
const { theme } = useTheme();
- const { isSubscribed, setUpgradeModalOpen } = useDashboardContext();
+ const { user, setUpgradeModalOpen } = useDashboardContext();
const { RiveComponent: CapAIArt } = useRive({
src: "/rive/bento.riv",
@@ -72,7 +72,7 @@ const CapAIDialog = ({ setOpen }: { setOpen: (open: boolean) => void }) => {
</div>
</div>
<DialogFooter>
- {!isSubscribed ? (
+ {!user.isPro ? (
<div className="flex gap-2 ml-auto">
<Button
autoFocus={false}
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
index 420e56ec6..a7ad28806 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
@@ -69,11 +69,8 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
];
const [dialogOpen, setDialogOpen] = useState(false);
- const {
- organizationData: orgData,
- activeOrganization: activeOrg,
- isSubscribed: userIsSubscribed,
- } = useDashboardContext();
+ const { organizationData: orgData, activeOrganization: activeOrg } =
+ useDashboardContext();
const formRef = useRef<HTMLFormElement | null>(null);
const [createLoading, setCreateLoading] = useState(false);
const [organizationName, setOrganizationName] = useState("");
@@ -307,7 +304,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
</div>
<div className="pb-4 mt-auto w-full">
<AnimatePresence>
- {!sidebarCollapsed && !userIsSubscribed && (
+ {!sidebarCollapsed && !user.isPro && (
<motion.div
initial={{ scale: 0 }}
animate={{ scale: 1 }}
@@ -327,7 +324,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
</AnimatePresence>
<UsageButton
toggleMobileNav={() => toggleMobileNav?.()}
- subscribed={userIsSubscribed}
+ subscribed={user.isPro}
/>
{buildEnv.NEXT_PUBLIC_IS_CAP && (
<div className="flex justify-center items-center mt-2">
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
index 5f1022bd2..4699c4b46 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
@@ -184,7 +184,7 @@ const Top = () => {
const User = () => {
const [menuOpen, setMenuOpen] = useState(false);
const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
- const { user, isSubscribed } = useDashboardContext();
+ const { user } = useDashboardContext();
const menuItems = useMemo(
() => [
@@ -204,7 +204,7 @@ const User = () => {
setUpgradeModalOpen(true);
},
iconClassName: "text-amber-400 group-hover:text-amber-500",
- showCondition: !isSubscribed && buildEnv.NEXT_PUBLIC_IS_CAP,
+ showCondition: buildEnv.NEXT_PUBLIC_IS_CAP && !user.isPro,
},
{
name: "Earn 40% Referral",
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 3f5272559..eb69e3db8 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -128,7 +128,7 @@ export const CapCard = ({
const [copyPressed, setCopyPressed] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [isSettingsDialogOpen, setIsSettingsDialogOpen] = useState(false);
- const { isSubscribed, setUpgradeModalOpen } = useDashboardContext();
+ const { user, setUpgradeModalOpen } = useDashboardContext();
const [confirmOpen, setConfirmOpen] = useState(false);
@@ -470,7 +470,7 @@ export const CapCard = ({
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
- if (!isSubscribed) setUpgradeModalOpen(true);
+ if (!user.isPro) setUpgradeModalOpen(true);
else setIsPasswordDialogOpen(true);
}}
className="flex gap-2 items-center rounded-lg"
diff --git a/apps/web/app/(org)/dashboard/layout.tsx b/apps/web/app/(org)/dashboard/layout.tsx
index 1446db6a9..a00a71d99 100644
--- a/apps/web/app/(org)/dashboard/layout.tsx
+++ b/apps/web/app/(org)/dashboard/layout.tsx
@@ -65,11 +65,6 @@ export default async function DashboardLayout({
activeOrganization = organizationSelect[0];
}
- const isSubscribed =
- (user.stripeSubscriptionId &&
- user.stripeSubscriptionStatus !== "cancelled") ||
- !!user.thirdPartyStripeSubscriptionId;
-
const theme = (await cookies()).get("theme")?.value ?? "light";
const sidebar = (await cookies()).get("sidebarCollapsed")?.value ?? "false";
const referClicked = (await cookies()).get("referClicked")?.value ?? "false";
@@ -83,7 +78,6 @@ export default async function DashboardLayout({
organizationData={organizationSelect}
activeOrganization={activeOrganization || null}
spacesData={spacesData}
- isSubscribed={isSubscribed}
initialTheme={theme as "light" | "dark"}
initialSidebarCollapsed={sidebar === "true"}
anyNewNotifications={anyNewNotifications}
diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx
index a2d9a784a..5c04c86f1 100644
--- a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx
+++ b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx
@@ -21,7 +21,7 @@ import CustomDomainDialog from "./CustomDomainDialog/CustomDomainDialog";
export function CustomDomain() {
const router = useRouter();
- const { activeOrganization, isSubscribed } = useDashboardContext();
+ const { activeOrganization, user } = useDashboardContext();
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
const [showCustomDomainDialog, setShowCustomDomainDialog] = useState(false);
const [confirmOpen, setConfirmOpen] = useState(false);
@@ -49,7 +49,7 @@ export function CustomDomain() {
});
const handleRemoveDomain = () => {
- if (!isSubscribed) {
+ if (!user.isPro) {
setShowUpgradeModal(true);
return;
}
diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx
index 3bb58a545..225aaceb3 100644
--- a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx
+++ b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/CustomDomainDialog.tsx
@@ -130,7 +130,7 @@ const CustomDomainDialog = ({
setIsVerified,
setShowUpgradeModal,
}: CustomDomainDialogProps) => {
- const { activeOrganization, isSubscribed } = useDashboardContext();
+ const { activeOrganization, user } = useDashboardContext();
const [domain, setDomain] = useState(
activeOrganization?.organization.customDomain || "",
);
@@ -378,7 +378,7 @@ const CustomDomainDialog = ({
<Stepper steps={steps} onStepClick={handleStepClick} />
<div className="relative w-full h-full">
- {!isSubscribed && <SubscribeContent />}
+ {!user.isPro && <SubscribeContent />}
<div className="p-5">
{/* Domain Step */}
@@ -441,7 +441,7 @@ const CustomDomainDialog = ({
{currentStep.id === "domain" && (
<>
- {isSubscribed ? (
+ {user.isPro ? (
<Button
onClick={handleDomainSubmit}
size="sm"
diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/DomainStep.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/DomainStep.tsx
index ebdfde0ae..a42ca2aa5 100644
--- a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/DomainStep.tsx
+++ b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomainDialog/DomainStep.tsx
@@ -19,7 +19,7 @@ const DomainStep = ({
onClearError,
submitLoading,
}: DomainStepProps) => {
- const { isSubscribed } = useDashboardContext();
+ const { user } = useDashboardContext();
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setDomain(e.target.value);
if (error) {
@@ -42,7 +42,7 @@ const DomainStep = ({
id="customDomain"
placeholder="caps.yourdomain.com"
value={domain}
- disabled={!isSubscribed || submitLoading}
+ disabled={!user.isPro || submitLoading}
className={clsx(
"max-w-[400px] mx-auto",
error && "border-red-500 focus:border-red-500",