239392b876
- lib/forum-sanitize.ts: cleanPostHtml con sanitize-html (misma allowlist que forum/sanitize.py de nh3: formato básico + a/img/tablas, rel nofollow, esquemas http/https/mailto). Verificado XSS-safe (script/onclick/javascript: eliminados). - lib/forum-write.ts: createTopic (tema + primer post), createPost (respuesta + updated_at), forumIsPostable / topicIsReplyable. - Routes /api/forum/topic y /api/forum/reply (guard de sesión; identidad = cuenta de juego: poster=username, poster_id=accountId). Componentes NewTopicForm y ReplyForm (clientes). Se muestran solo si hay sesión; el tema cerrado no admite respuesta. Verificado: escritura 401 sin sesión, saneado correcto. Pendiente: editar/borrar, moderación (fijar/cerrar/mover), búsqueda, editor enriquecido. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { notFound } from 'next/navigation'
|
|
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
|
import { Link } from '@/i18n/navigation'
|
|
import { getTopic, getPosts } from '@/lib/forum'
|
|
import { getSession } from '@/lib/session'
|
|
import { ReplyForm } from '@/components/ReplyForm'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export default async function TopicPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ locale: string; topicId: string }>
|
|
}) {
|
|
const { locale, topicId } = await params
|
|
setRequestLocale(locale)
|
|
const t = await getTranslations('Forum')
|
|
|
|
const id = Number(topicId)
|
|
const topic = await getTopic(id)
|
|
if (!topic) notFound()
|
|
const posts = await getPosts(id)
|
|
const session = await getSession()
|
|
const canReply = Boolean(session.username) && !topic!.locked
|
|
|
|
return (
|
|
<main className="mx-auto max-w-4xl px-4 py-8">
|
|
<p className="mb-2 text-sm">
|
|
<Link href="/forum" className="text-sky-400 hover:underline">
|
|
← {t('backToForum')}
|
|
</Link>
|
|
</p>
|
|
<h1 className="mb-6 text-2xl font-bold text-amber-500">
|
|
{topic!.locked && <span className="mr-2 text-sm text-red-400">[{t('locked')}]</span>}
|
|
{topic!.name}
|
|
</h1>
|
|
|
|
<div className="space-y-4">
|
|
{posts.map((post) => (
|
|
<article key={post.id} className="rounded-lg border border-amber-900/60 bg-[#241812] p-4">
|
|
<div className="mb-2 flex items-center justify-between border-b border-amber-900/40 pb-2 text-sm">
|
|
<span className="font-semibold text-amber-400">{post.poster}</span>
|
|
{post.time && (
|
|
<span className="text-amber-200/50">{new Date(post.time).toLocaleString(locale)}</span>
|
|
)}
|
|
</div>
|
|
<div
|
|
className="prose prose-invert max-w-none text-sm"
|
|
dangerouslySetInnerHTML={{ __html: post.text }}
|
|
/>
|
|
</article>
|
|
))}
|
|
</div>
|
|
|
|
{canReply ? (
|
|
<ReplyForm topicId={id} />
|
|
) : (
|
|
!session.username && <p className="mt-6 text-sm text-amber-200/60">{t('loginToPost')}</p>
|
|
)}
|
|
</main>
|
|
)
|
|
}
|