Foro: reemplazar el foro anterior por el port del foro estilo FusionCMS

Se sustituye por completo el foro anterior de Next (que estaba vacío: 0 temas, 0
posts) por una adaptación del foro PHP de FusionCMS que tenía el usuario, con su
estructura, sus imágenes y su estética, llevadas a Next.

BASE DE DATOS (acore_web), esquema idéntico al original (sql/forum_fusion.sql):
  forum_categories(id, order, name)
  forum_forums(id, category, order, name, description, icon, colortitle, type)
  forum_topics(id, forum, name, sticky, locked, deleted, created)
  forum_posts(id, topic, poster, text, time, deleted)
Se hizo DROP de las tablas antiguas (forums, forum_categories, forum_topics,
forum_posts) y CREATE de estas, con el seed original (News/Reports/General,
foros con icono, clases con color, subforos por idioma con bandera). Única
diferencia con el dump: forum_topics.created, que faltaba y usan las vistas, y
el recorte del salto de línea final en los nombres de clase.

Los temas no guardan autor ni última actividad: se derivan del primer/último post,
como en el original. `poster` es el AccountID de acore_auth; el nombre se resuelve
al render (username sin el sufijo #N de Battle.net). El texto se guarda como HTML
saneado con nh3 (no BBCode) para encajar con el editor.

EDITOR: TinyMCE community self-hosted (licenseKey gpl), servido desde /tinymce
(scripts/copy-tinymce.mjs en postinstall; public/tinymce en .gitignore por ser
artefacto). El HTML se sanea SIEMPRE en el servidor.

PÁGINAS (app/[locale]/forum): índice con los 3 tipos de foro (fila normal, tarjeta
de clase tipo 1, tarjeta de idioma tipo 2), subforo, tema, crear y editar. La
lógica de forum.js (crear/responder/editar/moderar) se portó a fetch + los avisos
del sitio, sin jQuery/SweetAlert, y la moderación pasa por POST (no GET).

CSS: forum.css adaptado al tema (app/forum.css), rutas de imagen a /forum, dorado
alineado al acento del sitio (#d79602), y se aportan .nice_button/.main-wide/
.pagination que no estaban en theme.css.

ADMIN: lib/admin-forum.ts, sus rutas y AdminForumManager reescritos al esquema
nuevo (categoría, icono, color, tipo, orden; sin _en/visibility).

Se eliminan /forum/search y /forum/user (no existen en el foro nuevo) y los
componentes que quedaban huérfanos (ForumSearchBox, PostActions, TopicModBar,
NewTopicForm). i18n ES/EN completado (next-intl).

Verificado en producción: el índice renderiza en es/en con categorías, clases,
banderas e iconos; los assets y TinyMCE sirven 200; crear tema y responder guardan
las filas con el esquema correcto y las páginas las muestran (autor resuelto, HTML
saneado). Datos de prueba borrados: el foro arranca vacío.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-16 12:22:08 +00:00
parent 0f98b754d4
commit af707ad98c
190 changed files with 3142 additions and 1104 deletions
+19 -22
View File
@@ -1,23 +1,13 @@
import { getSession } from '@/lib/session'
import { isAdmin } from '@/lib/admin'
import { deleteForum, setForumVisibility, updateForum } from '@/lib/admin-forum'
import { deleteForum, updateForum } from '@/lib/admin-forum'
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const { id } = await params
await deleteForum(Number(id))
return Response.json({ success: true })
}
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const { id } = await params
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
await setForumVisibility(Number(id), b.visibility !== false)
return Response.json({ success: true })
const ok = await deleteForum(Number(id))
return Response.json({ success: ok, error: ok ? undefined : 'forumNotEmpty' })
}
export async function PUT(request: Request, { params }: { params: Promise<{ id: string }> }) {
@@ -25,14 +15,21 @@ export async function PUT(request: Request, { params }: { params: Promise<{ id:
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const { id } = await params
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const name = String(b.name ?? '').trim()
const nameEn = String(b.nameEn ?? '').trim() || null
const description = String(b.description ?? '').trim()
const descriptionEn = String(b.descriptionEn ?? '').trim() || null
const order = Number(b.order) || 0
const visibility = b.visibility === false ? 0 : 1
if (!name) return Response.json({ success: false, error: 'emptyError' })
await updateForum(Number(id), name, nameEn, description, descriptionEn, order, visibility)
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const f = {
category: Number(b.category),
name: String(b.name ?? '').trim(),
description: String(b.description ?? '').trim(),
icon: String(b.icon ?? '').trim() || null,
colortitle: String(b.colortitle ?? '').trim() || null,
type: Number(b.type) || 0,
order: Number(b.order) || 0,
}
if (!f.category || !f.name) return Response.json({ success: false, error: 'emptyError' })
await updateForum(Number(id), f)
return Response.json({ success: true })
}
@@ -15,11 +15,14 @@ export async function PUT(request: Request, { params }: { params: Promise<{ id:
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const { id } = await params
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const name = String(b.name ?? '').trim()
const nameEn = String(b.nameEn ?? '').trim() || null
const order = Number(b.order) || 0
if (!name) return Response.json({ success: false, error: 'emptyError' })
await updateCategory(Number(id), name, nameEn, order)
await updateCategory(Number(id), name, order)
return Response.json({ success: true })
}
@@ -6,11 +6,14 @@ export async function POST(request: Request) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const name = String(b.name ?? '').trim()
const nameEn = String(b.nameEn ?? '').trim() || null
const order = Number(b.order) || 0
if (!name) return Response.json({ success: false, error: 'emptyError' })
const id = await createCategory(name, nameEn, order)
const id = await createCategory(name, order)
return Response.json({ success: true, id })
}
+16 -10
View File
@@ -6,15 +6,21 @@ export async function POST(request: Request) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const categoryId = Number(b.categoryId)
const name = String(b.name ?? '').trim()
const nameEn = String(b.nameEn ?? '').trim() || null
const description = String(b.description ?? '').trim()
const descriptionEn = String(b.descriptionEn ?? '').trim() || null
const order = Number(b.order) || 0
const visibility = b.visibility === false ? 0 : 1
if (!categoryId || !name) return Response.json({ success: false, error: 'emptyError' })
const id = await createForum(categoryId, name, nameEn, description, descriptionEn, order, visibility)
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const f = {
category: Number(b.category),
name: String(b.name ?? '').trim(),
description: String(b.description ?? '').trim(),
icon: String(b.icon ?? '').trim() || null,
colortitle: String(b.colortitle ?? '').trim() || null,
type: Number(b.type) || 0,
order: Number(b.order) || 0,
}
if (!f.category || !f.name) return Response.json({ success: false, error: 'emptyError' })
const id = await createForum(f)
return Response.json({ success: true, id })
}
+35 -36
View File
@@ -1,55 +1,54 @@
import { getSession } from '@/lib/session'
import { getTopic, getForum } from '@/lib/forum'
import { setTopicFlag, moveTopic } from '@/lib/forum-write'
import { getTopic } from '@/lib/forum'
import { getPost, setTopicFlag, setPostDeleted } from '@/lib/forum-write'
import { forumIsModerator } from '@/lib/forum-perm'
type Action = 'lock' | 'unlock' | 'sticky' | 'unsticky' | 'delete' | 'restore' | 'move'
/** Moderación de temas: bloquear, fijar, borrar. Solo moderadores. */
/**
* Moderación del foro (solo moderadores), por POST para no mutar con GET.
* kind='post' → action: delete | undelete
* kind='topic' → action: delete | undelete | lock | unlock
*/
export async function POST(request: Request) {
const session = await getSession()
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
if (!(await forumIsModerator(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const topicId = Number(b.topicId)
const action = String(b.action ?? '') as Action
if (!topicId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const kind = String(b.kind ?? '')
const id = Number(b.id)
const action = String(b.action ?? '')
if (!id || (kind !== 'post' && kind !== 'topic'))
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
const topic = await getTopic(topicId, true) // incluye borrados (ya verificado que es mod)
if (kind === 'post') {
const post = await getPost(id)
if (!post) return Response.json({ success: false, error: 'postNotFound' }, { status: 404 })
if (action === 'delete') await setPostDeleted(id, true)
else if (action === 'undelete') await setPostDeleted(id, false)
else return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
return Response.json({ success: true })
}
const topic = await getTopic(id, true)
if (!topic) return Response.json({ success: false, error: 'topicNotFound' }, { status: 404 })
switch (action) {
case 'delete':
await setTopicFlag(id, 'deleted', true)
break
case 'undelete':
await setTopicFlag(id, 'deleted', false)
break
case 'lock':
await setTopicFlag(topicId, 'locked', true)
await setTopicFlag(id, 'locked', true)
break
case 'unlock':
await setTopicFlag(topicId, 'locked', false)
await setTopicFlag(id, 'locked', false)
break
case 'sticky':
await setTopicFlag(topicId, 'sticky', true)
break
case 'unsticky':
await setTopicFlag(topicId, 'sticky', false)
break
case 'delete':
await setTopicFlag(topicId, 'deleted', true)
return Response.json({ success: true, forumId: topic.forum_id })
case 'restore':
await setTopicFlag(topicId, 'deleted', false)
break
case 'move': {
const newForumId = Number(b.forumId)
if (!newForumId || newForumId === topic.forum_id) {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
if (!(await getForum(newForumId))) {
return Response.json({ success: false, error: 'invalidForum' }, { status: 400 })
}
await moveTopic(topicId, newForumId)
return Response.json({ success: true })
}
default:
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
+11 -44
View File
@@ -1,25 +1,10 @@
import { getSession } from '@/lib/session'
import { getPost, updatePost, setPostDeleted } from '@/lib/forum-write'
import { getPost, updatePost } from '@/lib/forum-write'
import { getTopic } from '@/lib/forum'
import { forumIsModerator, canEditPost } from '@/lib/forum-perm'
import { plainLength } from '@/lib/forum-sanitize'
const MIN_TEXT_LEN = 5
/** Restaurar un post borrado. Solo moderadores. */
export async function PUT(request: Request) {
const session = await getSession()
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
if (!(await forumIsModerator(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const postId = Number(b.postId)
if (!postId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
await setPostDeleted(postId, false)
return Response.json({ success: true })
}
const MIN_TEXT_LEN = 3
/** Editar el texto de un post propio (o cualquiera si es moderador). */
export async function PATCH(request: Request) {
@@ -27,44 +12,26 @@ export async function PATCH(request: Request) {
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const postId = Number(b.postId)
const text = String(b.text ?? '').trim()
const text = String(b.text ?? '')
if (!postId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
const post = await getPost(postId)
if (!post) return Response.json({ success: false, error: 'postNotFound' }, { status: 404 })
const isMod = await forumIsModerator(session)
if (!canEditPost(session, isMod, post.poster_id)) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
if (!canEditPost(session, isMod, post.poster))
return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const topic = await getTopic(post.topic_id)
const topic = await getTopic(post.topic)
if (topic?.locked && !isMod) return Response.json({ success: false, error: 'topicLocked' })
if (plainLength(text) < MIN_TEXT_LEN) return Response.json({ success: false, error: 'tooShort' })
await updatePost(postId, text)
return Response.json({ success: true })
}
/** Borrar (lógico) un post propio (o cualquiera si es moderador). */
export async function DELETE(request: Request) {
const session = await getSession()
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const postId = Number(b.postId)
if (!postId) return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
const post = await getPost(postId)
if (!post) return Response.json({ success: false, error: 'postNotFound' }, { status: 404 })
const isMod = await forumIsModerator(session)
if (!canEditPost(session, isMod, post.poster_id)) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const topic = await getTopic(post.topic_id)
if (topic?.locked && !isMod) return Response.json({ success: false, error: 'topicLocked' })
await setPostDeleted(postId, true)
return Response.json({ success: true })
}
+11 -5
View File
@@ -1,15 +1,21 @@
import { getSession } from '@/lib/session'
import { createPost, topicIsReplyable } from '@/lib/forum-write'
import { plainLength } from '@/lib/forum-sanitize'
export async function POST(request: Request) {
const session = await getSession()
if (!session.accountId || !session.username) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
if (!session.accountId || !session.username)
return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const topicId = Number(b.topicId)
const text = String(b.text ?? '').trim()
if (!topicId || !text) return Response.json({ success: false, error: 'emptyError' })
const text = String(b.text ?? '')
if (!topicId || plainLength(text) < 3) return Response.json({ success: false, error: 'emptyError' })
if (!(await topicIsReplyable(topicId))) return Response.json({ success: false, error: 'topicLocked' })
await createPost(topicId, session.username, session.accountId, text)
await createPost(topicId, session.accountId, text)
return Response.json({ success: true })
}
+16 -8
View File
@@ -1,16 +1,24 @@
import { getSession } from '@/lib/session'
import { createTopic, forumIsPostable } from '@/lib/forum-write'
import { createTopic } from '@/lib/forum-write'
import { forumExists } from '@/lib/forum'
import { plainLength } from '@/lib/forum-sanitize'
export async function POST(request: Request) {
const session = await getSession()
if (!session.accountId || !session.username) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
if (!session.accountId || !session.username)
return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
let b: Record<string, string> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
try {
b = await request.json()
} catch {
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
}
const forumId = Number(b.forumId)
const name = String(b.name ?? '').trim()
const text = String(b.text ?? '').trim()
if (!forumId || !name || !text) return Response.json({ success: false, error: 'emptyError' })
if (!(await forumIsPostable(forumId))) return Response.json({ success: false, error: 'invalidForum' })
const topicId = await createTopic(forumId, name, session.username, session.accountId, text)
const title = String(b.title ?? '').trim()
const text = String(b.text ?? '')
if (!forumId || title.length < 3) return Response.json({ success: false, error: 'errTitle' })
if (plainLength(text) < 3) return Response.json({ success: false, error: 'emptyError' })
if (!(await forumExists(forumId))) return Response.json({ success: false, error: 'invalidForum' })
const topicId = await createTopic(forumId, title, session.accountId, text)
return Response.json({ success: true, topicId })
}