feat: Implement AI-powered comment rewriting and a collapsible comment form for user feedback.
This commit is contained in:
@@ -10,7 +10,7 @@ export async function POST(request: NextRequest) {
|
||||
if (rateLimitError) return rateLimitError;
|
||||
|
||||
try {
|
||||
const { puzzleId, genreId, message, playerIdentifier } = await request.json();
|
||||
const { puzzleId, genreId, message, playerIdentifier, originalMessage } = await request.json();
|
||||
|
||||
// Validate required fields
|
||||
if (!puzzleId || !message || !playerIdentifier) {
|
||||
@@ -28,9 +28,9 @@ export async function POST(request: NextRequest) {
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (trimmedMessage.length > 2000) {
|
||||
if (trimmedMessage.length > 300) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Message too long. Maximum 2000 characters allowed.' },
|
||||
{ error: 'Message too long. Maximum 300 characters allowed.' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -170,13 +170,26 @@ export async function POST(request: NextRequest) {
|
||||
return comment;
|
||||
});
|
||||
|
||||
// Send Gotify notification (fire and forget)
|
||||
const { sendCommentNotification } = await import('@/app/actions');
|
||||
// originalMessage is already available from the initial request.json() call
|
||||
|
||||
// Determine genre name for notification
|
||||
let genreName: string | null = null;
|
||||
if (finalGenreId) {
|
||||
const genreObj = await prisma.genre.findUnique({ where: { id: finalGenreId } });
|
||||
if (genreObj) genreName = genreObj.name as string;
|
||||
}
|
||||
|
||||
sendCommentNotification(Number(puzzleId), trimmedMessage, originalMessage, genreName || null);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
commentId: result.id
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating curator comment:', error);
|
||||
|
||||
|
||||
// Handle unique constraint violation (shouldn't happen due to our check, but just in case)
|
||||
if (error instanceof Error && error.message.includes('Unique constraint')) {
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user