add user settings

This commit is contained in:
Garret Patti
2026-04-05 18:15:08 -04:00
parent eecee9bc5f
commit 5b5503b7a6
11 changed files with 363 additions and 9 deletions

View File

@@ -0,0 +1,39 @@
import { NextRequest, NextResponse } from 'next/server'
import { requireAuth } from '@/lib/auth'
import { getUserSettings, updateUserSettings } from '@/lib/settings'
import type { UserSettings } from '@/types'
export async function GET(req: NextRequest) {
const auth = await requireAuth(req)
if (auth instanceof NextResponse) return auth
const settings = getUserSettings(auth.session.userId)
return NextResponse.json(settings)
}
export async function PUT(req: NextRequest) {
const auth = await requireAuth(req)
if (auth instanceof NextResponse) return auth
let body: unknown
try {
body = await req.json()
} catch {
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })
}
const s = body as Record<string, unknown>
const boolFields: (keyof UserSettings)[] = [
'mixedAutoplay', 'mixedLoop', 'mixedMuted',
'moviesAutoplay', 'moviesLoop', 'moviesMuted',
'tvAutoplay', 'tvLoop', 'tvMuted',
]
for (const field of boolFields) {
if (typeof s[field] !== 'boolean') {
return NextResponse.json({ error: `Invalid value for ${field}` }, { status: 400 })
}
}
updateUserSettings(auth.session.userId, s as unknown as UserSettings)
return NextResponse.json({ ok: true })
}