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

50 lines
1.5 KiB
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({ error: 'FID required' }, { status: 400 })
const settings = await redis.get(`settings:${fid}`)
return NextResponse.json(settings || {
notifyOnVote: true,
notifyOnComment: true,
notifyOnFollow: true,
notifyOnWin: true
})
} catch (error) {
console.error('Settings GET error:', error)
return NextResponse.json({ error: 'Failed to fetch settings' }, { status: 500 })
}
}
export async function PUT(req: NextRequest) {
try {
const body = await req.json()
const { fid, ...settings } = body
if (!fid) return NextResponse.json({ error: 'FID required' }, { status: 400 })
await redis.set(`settings:${fid}`, JSON.stringify(settings))
if (settings.displayName || settings.bio) {
const userData = await redis.get(`user:${fid}`)
const user = userData ? (typeof userData === 'string' ? JSON.parse(userData) : userData) : {}
await redis.set(`user:${fid}`, JSON.stringify({
...user,
displayName: settings.displayName,
bio: settings.bio
}))
}
return NextResponse.json({ success: true })
} catch (error) {
console.error('Settings PUT error:', error)
return NextResponse.json({ error: 'Failed to update settings' }, { status: 500 })
}
}