d5b00a86dc
- lib/admin.ts: isAdmin(session) por allowlist ADMIN_EMAILS (normalizada) o gmlevel de AzerothCore (account_access, resiliente si no existe). ADMIN_EMAILS/ADMIN_GMLEVEL en .env.local. - lib/admin-news.ts: listNews / createNews / deleteNews (home_noticia). - Routes /api/admin/news (POST, guard isAdmin) y /api/admin/news/[id] (DELETE). - Páginas /admin (dashboard) y /admin/news (protegidas: no-admin -> redirect). AdminNewsManager (cliente: crear + listar + borrar). Verificado: /admin sin permiso redirige, APIs 403; el pipeline crear noticia -> se renderiza en la home (SSR) funciona. Turnstile bloquea el login por curl (correcto). Pendiente admin: precios de servicios, foros, sitios de voto, usuarios. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { RowDataPacket, ResultSetHeader } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
|
|
export interface NewsItem {
|
|
id: number
|
|
titulo: string
|
|
fecha: string | null
|
|
enlace: string | null
|
|
}
|
|
|
|
export async function listNews(): Promise<NewsItem[]> {
|
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT id, titulo, fecha_publicacion, enlace FROM home_noticia ORDER BY fecha_publicacion DESC',
|
|
)
|
|
return rows.map((r) => ({
|
|
id: r.id,
|
|
titulo: r.titulo,
|
|
fecha: r.fecha_publicacion ? new Date(r.fecha_publicacion).toISOString() : null,
|
|
enlace: r.enlace || null,
|
|
}))
|
|
}
|
|
|
|
export async function createNews(titulo: string, contenido: string, enlace: string | null): Promise<number> {
|
|
const [res] = await db(DB.default).query<ResultSetHeader>(
|
|
'INSERT INTO home_noticia (titulo, contenido, fecha_publicacion, enlace) VALUES (?, ?, NOW(), ?)',
|
|
[titulo, contenido, enlace || null],
|
|
)
|
|
return res.insertId
|
|
}
|
|
|
|
export async function deleteNews(id: number): Promise<void> {
|
|
await db(DB.default).query('DELETE FROM home_noticia WHERE id = ?', [id])
|
|
}
|