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

21 lines
673 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { redis } from '@/lib/redis'
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url)
const fid = searchParams.get('fid')
if (!fid) return NextResponse.json({ count: 0 })
const notificationsData = await redis.lrange(`notifications:${fid}`, 0, -1)
const notifications = notificationsData.map(n => JSON.parse(n))
const unreadCount = notifications.filter(n => !n.read).length
return NextResponse.json({ count: unreadCount })
} catch (error) {
console.error('Unread count error:', error)
return NextResponse.json({ count: 0 })
}
}