From 7158ead89a5ee0431b53d373eb7b6eb06b6f9d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Kadir=20Ak=C4=B1n?= Date: Sat, 20 Dec 2025 18:31:32 +0300 Subject: [PATCH] feat(api): Enable comments feature in prompts configuration --- prompts.config.ts | 6 ++++-- .../[id]/comments/[commentId]/flag/route.ts | 9 +++++++++ .../prompts/[id]/comments/[commentId]/route.ts | 9 +++++++++ .../[id]/comments/[commentId]/vote/route.ts | 17 +++++++++++++++++ src/app/api/prompts/[id]/comments/route.ts | 17 +++++++++++++++++ src/app/prompts/[id]/page.tsx | 4 +++- src/lib/config/index.ts | 2 ++ 7 files changed, 61 insertions(+), 3 deletions(-) diff --git a/prompts.config.ts b/prompts.config.ts index fed49d8b..ae1f6e34 100644 --- a/prompts.config.ts +++ b/prompts.config.ts @@ -59,11 +59,13 @@ export default defineConfig({ // Enable tags tags: true, // Enable AI-powered semantic search (requires OPENAI_API_KEY) - aiSearch: true, + aiSearch: false, // Enable AI-powered generation features (requires OPENAI_API_KEY) - aiGeneration: true, + aiGeneration: false, // Enable MCP (Model Context Protocol) features including API key generation mcp: true, + // Enable comments on prompts + comments: true, }, // Homepage customization diff --git a/src/app/api/prompts/[id]/comments/[commentId]/flag/route.ts b/src/app/api/prompts/[id]/comments/[commentId]/flag/route.ts index 58a32b91..01fee766 100644 --- a/src/app/api/prompts/[id]/comments/[commentId]/flag/route.ts +++ b/src/app/api/prompts/[id]/comments/[commentId]/flag/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/lib/auth"; import { db } from "@/lib/db"; +import { getConfig } from "@/lib/config"; // POST - Flag a comment (admin only) export async function POST( @@ -8,6 +9,14 @@ export async function POST( { params }: { params: Promise<{ id: string; commentId: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const session = await auth(); if (!session?.user) { return NextResponse.json( diff --git a/src/app/api/prompts/[id]/comments/[commentId]/route.ts b/src/app/api/prompts/[id]/comments/[commentId]/route.ts index 9d1b9e81..6ae5c06f 100644 --- a/src/app/api/prompts/[id]/comments/[commentId]/route.ts +++ b/src/app/api/prompts/[id]/comments/[commentId]/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/lib/auth"; import { db } from "@/lib/db"; +import { getConfig } from "@/lib/config"; // DELETE - Delete a comment (author or admin only) export async function DELETE( @@ -8,6 +9,14 @@ export async function DELETE( { params }: { params: Promise<{ id: string; commentId: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const session = await auth(); if (!session?.user) { return NextResponse.json( diff --git a/src/app/api/prompts/[id]/comments/[commentId]/vote/route.ts b/src/app/api/prompts/[id]/comments/[commentId]/vote/route.ts index 9fde9098..2053a6c1 100644 --- a/src/app/api/prompts/[id]/comments/[commentId]/vote/route.ts +++ b/src/app/api/prompts/[id]/comments/[commentId]/vote/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/lib/auth"; import { db } from "@/lib/db"; +import { getConfig } from "@/lib/config"; import { z } from "zod"; const voteSchema = z.object({ @@ -15,6 +16,14 @@ export async function POST( { params }: { params: Promise<{ id: string; commentId: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const session = await auth(); if (!session?.user) { return NextResponse.json( @@ -136,6 +145,14 @@ export async function DELETE( { params }: { params: Promise<{ id: string; commentId: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const session = await auth(); if (!session?.user) { return NextResponse.json( diff --git a/src/app/api/prompts/[id]/comments/route.ts b/src/app/api/prompts/[id]/comments/route.ts index e85e140a..83b619ac 100644 --- a/src/app/api/prompts/[id]/comments/route.ts +++ b/src/app/api/prompts/[id]/comments/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/lib/auth"; import { db } from "@/lib/db"; +import { getConfig } from "@/lib/config"; import { z } from "zod"; const createCommentSchema = z.object({ @@ -14,6 +15,14 @@ export async function GET( { params }: { params: Promise<{ id: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const { id: promptId } = await params; const session = await auth(); @@ -115,6 +124,14 @@ export async function POST( { params }: { params: Promise<{ id: string }> } ) { try { + const config = await getConfig(); + if (config.features.comments === false) { + return NextResponse.json( + { error: "feature_disabled", message: "Comments are disabled" }, + { status: 403 } + ); + } + const session = await auth(); if (!session?.user) { return NextResponse.json( diff --git a/src/app/prompts/[id]/page.tsx b/src/app/prompts/[id]/page.tsx index 1468bb25..3e06118e 100644 --- a/src/app/prompts/[id]/page.tsx +++ b/src/app/prompts/[id]/page.tsx @@ -24,6 +24,7 @@ import { MediaPreview } from "@/components/prompts/media-preview"; import { ReportPromptDialog } from "@/components/prompts/report-prompt-dialog"; import { DelistBanner } from "@/components/prompts/delist-banner"; import { CommentSection } from "@/components/comments"; +import { getConfig } from "@/lib/config"; interface PromptPageProps { params: Promise<{ id: string }>; @@ -70,6 +71,7 @@ export default async function PromptPage({ params }: PromptPageProps) { const { id: idParam } = await params; const id = extractPromptId(idParam); const session = await auth(); + const config = await getConfig(); const t = await getTranslations("prompts"); const locale = await getLocale(); @@ -594,7 +596,7 @@ export default async function PromptPage({ params }: PromptPageProps) { {/* Comments Section */} - {!prompt.isPrivate && ( + {config.features.comments !== false && !prompt.isPrivate && ( { tags: true, aiSearch: false, aiGeneration: false, + comments: true, }, }; return cachedConfig;