Página de votación de usuario (/vote-points) + enlace en cabecera

- lib/vote.ts: getVoteSites (home_votesite), registerVote (cooldown 12h30 vía
  home_votelog, acredita PV en home_api_points, registra el voto).
- Route /api/vote (POST {url}, guard sesión). Página /vote-points (VotePanel:
  abre el sitio + registra el voto, muestra PV/cooldown). Enlace "Votar" en cabecera.
- Cierra el ciclo con el admin de sitios de voto.

Verificado: /vote-points 200, POST 401 sin sesión; lógica probada: voto -> +PV,
segundo voto -> cooldown 12h29m.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-13 00:06:57 +00:00
parent 934bee2aec
commit f9609aad99
7 changed files with 211 additions and 2 deletions
@@ -0,0 +1,21 @@
import { getTranslations, setRequestLocale } from 'next-intl/server'
import { getSession } from '@/lib/session'
import { getVoteSites } from '@/lib/vote'
import { VotePanel } from '@/components/VotePanel'
export const dynamic = 'force-dynamic'
export default async function VotePointsPage({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params
setRequestLocale(locale)
const t = await getTranslations('Vote')
const session = await getSession()
const sites = await getVoteSites()
return (
<main className="mx-auto max-w-3xl px-4 py-8">
<h1 className="mb-3 text-2xl font-bold text-amber-500">{t('title')}</h1>
<p className="mb-6 text-sm text-amber-200/70">{t('info', { server: 'Nova WoW' })}</p>
<VotePanel sites={sites} canVote={Boolean(session.accountId)} />
</main>
)
}
+16
View File
@@ -0,0 +1,16 @@
import { getSession } from '@/lib/session'
import { registerVote } from '@/lib/vote'
export async function POST(request: Request) {
const session = await getSession()
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
let url = ''
try {
const b = await request.json()
url = String(b.url ?? '')
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
if (!url) return Response.json({ success: false, error: 'siteNotFound' })
return Response.json(await registerVote(session.accountId, url))
}