Skip to content

Commit

Permalink
Merge pull request #39 from ShreyTanna29/free
Browse files Browse the repository at this point in the history
made curious ai free for all users
  • Loading branch information
ShreyTanna29 authored Nov 25, 2024
2 parents 65fe97d + b2ace36 commit d31537b
Show file tree
Hide file tree
Showing 24 changed files with 26 additions and 601 deletions.
8 changes: 1 addition & 7 deletions app/(dashboard)/(routes)/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Loader from "@/components/loader";
import { cn } from "@/packages/utils";
import UserAvatar from "@/components/user.avatar";
import BotAvatar from "@/components/bot.avatar";
import { useProModel } from "@/hooks/useProModel";
import toast from "react-hot-toast";
import ReactMarkdown from "react-markdown";

Expand All @@ -26,7 +25,6 @@ type Message = {
};

function ConversationPage() {
const proModel = useProModel();
const router = useRouter();
const [messages, setMessages] = useState<Message[]>([]);
const [gettingUserChats, setGettingUserChats] = useState(false);
Expand Down Expand Up @@ -77,11 +75,7 @@ function ConversationPage() {
form.reset();
} catch (error: any) {
console.log(error);
if (error?.response?.status === 403) {
proModel.onOpen();
} else {
toast.error("Something went wrong.");
}
toast.error("Something went wrong.");
} finally {
router.refresh();
}
Expand Down
8 changes: 1 addition & 7 deletions app/(dashboard)/(routes)/code/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { cn } from "@/packages/utils";
import UserAvatar from "@/components/user.avatar";
import BotAvatar from "@/components/bot.avatar";
import ReactMarkdown from "react-markdown";
import { useProModel } from "@/hooks/useProModel";
import toast from "react-hot-toast";

type Message = {
Expand All @@ -27,7 +26,6 @@ type Message = {

function CodeGenerationPage() {
const router = useRouter();
const proModel = useProModel();
const [messages, setMessages] = useState<Message[]>([]);
const [gettingUserCode, setGettingUserCode] = useState(false);
const form = useForm<z.infer<typeof formSchema>>({
Expand Down Expand Up @@ -77,11 +75,7 @@ function CodeGenerationPage() {
form.reset();
} catch (error: any) {
console.log(error);
if (error?.response?.status === 403) {
proModel.onOpen();
} else {
toast.error("Something went wrong.");
}
toast.error("Something went wrong.");
} finally {
router.refresh();
}
Expand Down
11 changes: 3 additions & 8 deletions app/(dashboard)/(routes)/image/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { useEffect, useState } from "react";
import Empty from "@/components/empty";
import Loader from "@/components/loader";
import { Card, CardFooter } from "@/components/ui/card";
import { useProModel } from "@/hooks/useProModel";
import toast from "react-hot-toast";
import {
DropdownMenu,
Expand All @@ -41,7 +40,6 @@ type imageType = {

function ImagePage() {
const router = useRouter();
const proModel = useProModel();
const [images, setImages] = useState<imageType[]>([]);
const [loadingImages, setLoadingImages] = useState(true)
const [deletingImages, setDeletingImages] = useState<{
Expand Down Expand Up @@ -92,12 +90,9 @@ function ImagePage() {
form.reset();
} catch (error: any) {
console.log(error);
if (error?.response?.status === 403) {
proModel.onOpen();
} else {
toast.error("Please write another prompt.");
}
} finally {
toast.error("Something went wrong.");
}
finally {
router.refresh();
}
};
Expand Down
8 changes: 2 additions & 6 deletions app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import MobileSidebar from "@/components/mobile-sidebar";
import Sidebar from "@/components/sidebar";
import { getApiLimitCount } from "@/packages/api/api-limit";
import { checkSubscription } from "@/packages/features/subscription";

const DashboardLayout = async ({ children }: { children: React.ReactNode }) => {
const apiLimitCount = await getApiLimitCount();
const isPro = await checkSubscription();
return (
<div className="h-full relative">
<div className="hidden h-full md:flex md:w-72 md:flex-col md:fixed md:inset-y-0 bg-gray-900">
<Sidebar apiLimitCount={apiLimitCount!} isPro={isPro} />
<Sidebar />
</div>
<main className="md:pl-72 m-2">
<MobileSidebar apiLimitCount={apiLimitCount!} isPro={isPro} />
<MobileSidebar />
{children}
</main>
</div>
Expand Down
13 changes: 0 additions & 13 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
import { GoogleGenerativeAI } from "@google/generative-ai";
import { checkApiLimit, increaseApiLimit } from "@/packages/api/api-limit";
import { checkSubscription } from "@/packages/features/subscription";
import prismadb from "@/packages/api/prismadb";

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || "");
Expand All @@ -21,23 +19,12 @@ export async function POST(req: Request) {
return new NextResponse("prompt is required", { status: 400 });
}

const freeTrail = await checkApiLimit();
const isPro = await checkSubscription();

if (!freeTrail && !isPro) {
return new NextResponse("Free trail has expired", { status: 403 });
}

const model = genAI.getGenerativeModel({ model: "gemini-pro" });

const chat = model.startChat();
const result = await chat.sendMessage(prompt);
const response = result.response.candidates?.[0].content.parts[0].text;

if (!isPro) {
await increaseApiLimit();
}

await prismadb.chat.create({
data: {
userId,
Expand Down
13 changes: 0 additions & 13 deletions app/api/code/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
import { GoogleGenerativeAI } from "@google/generative-ai";
import { checkApiLimit, increaseApiLimit } from "@/packages/api/api-limit";
import { checkSubscription } from "@/packages/features/subscription";
import prismadb from "@/packages/api/prismadb";

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || "");
Expand All @@ -21,13 +19,6 @@ export async function POST(req: Request) {
return new NextResponse("prompt is required", { status: 400 });
}

const freeTrail = await checkApiLimit();
const isPro = await checkSubscription();

if (!freeTrail && !isPro) {
return new NextResponse("Free trail has expired", { status: 403 });
}

const model = genAI.getGenerativeModel({ model: "gemini-pro" });

const chat = model.startChat();
Expand All @@ -36,10 +27,6 @@ export async function POST(req: Request) {
);
const response = result.response.candidates?.[0].content.parts[0].text;

if (!isPro) {
await increaseApiLimit();
}

await prismadb.code.create({
data: {
userId,
Expand Down
14 changes: 0 additions & 14 deletions app/api/image/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
import axios from "axios";
import { checkApiLimit, increaseApiLimit } from "@/packages/api/api-limit";
import { checkSubscription } from "@/packages/features/subscription";
import prismadb from "@/packages/api/prismadb";

export async function POST(req: Request) {
Expand All @@ -21,13 +19,6 @@ export async function POST(req: Request) {
return new NextResponse("Prompt is required.", { status: 400 });
}

const freeTrail = await checkApiLimit();
const isPro = await checkSubscription();

if (!freeTrail && !isPro) {
return new NextResponse("Free trail has expired", { status: 403 });
}

const response = await axios.post(
url,
{
Expand All @@ -46,11 +37,6 @@ export async function POST(req: Request) {
}
);

if (!isPro) {
await increaseApiLimit();
}


const imgUrl = await response.data.output[0].url;

await prismadb.image.create({
Expand Down
63 changes: 0 additions & 63 deletions app/api/stripe/route.ts

This file was deleted.

68 changes: 0 additions & 68 deletions app/api/webhooks/route.ts

This file was deleted.

2 changes: 0 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
import { ClerkProvider } from "@clerk/nextjs";
import { ModalProvider } from "@/components/modalProvider";
import { ToasterProvider } from "@/components/toaster.provider";
import { CrispProvider } from "@/components/crisp-provider";
import NextTopLoader from 'nextjs-toploader';
Expand Down Expand Up @@ -38,7 +37,6 @@ export default function RootLayout({
className={`${geistSans.variable} dark:bg-black ${geistMono.variable} antialiased`}
>
<NextTopLoader showSpinner={false} />
<ModalProvider />
<ToasterProvider />
{children}
</body>
Expand Down
Loading

0 comments on commit d31537b

Please sign in to comment.