2025-12-08 16:31:30 +03:00

29 lines
806 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { redis } from '@/lib/redis'
export async function GET(req: NextRequest, { params }: { params: { id: string } }) {
try {
const { id: parentId } = params
const allComments = await redis.keys('comments:*')
const replies = []
for (const key of allComments) {
const comments = await redis.lrange(key, 0, -1)
for (const commentStr of comments) {
const comment = JSON.parse(commentStr)
if (comment.parentId === parentId) {
replies.push(comment)
}
}
}
replies.sort((a, b) => b.timestamp - a.timestamp)
return NextResponse.json({ replies })
} catch (error) {
console.error('Replies API error:', error)
return NextResponse.json({ replies: [] })
}
}