Forums-Anträge erfassen und von Hand entscheiden

Der GExtension-Abgleich liefert die Käufe, der Verbrauch steht im Forum. Die
App liest jetzt die drei CC-Boards und sammelt die Anträge.

Gelesen wird nur die Board-Übersicht: sie führt bereits den Ersteller, nicht
nur den letzten Antwortenden. Damit bleibt ein Lauf bei wenigen Anfragen statt
einer je Thread. Unterforen und globale Kästen tragen ebenfalls Thread-Links,
deshalb liest der Parser strikt entlang der Listeneinträge - sonst landen
Changelogs und Bewerbungen in der Antragsliste.

Klassifiziert wird ausschließlich von Hand. Weder Titel noch Board sind
verlässlich genug: Threads werden nicht immer verschoben, ein genehmigter
Antrag kann weiter im Antrags-Board liegen. Das Board steht deshalb nur als
Hinweis an der Zeile.

Angenommene Anträge rufen dieselben Aktionen wie die Knöpfe auf der
Spielerseite, es gibt keinen zweiten Buchungsweg mit eigenen Regeln. Wandert
ein bereits entschiedener Thread später in ein anderes Board, erscheint das
als Hinweis zum Abhaken - der CC-Status ändert sich nie von allein.

Die Thread-ID bleibt beim Verschieben stabil und traegt deshalb die
Wiedererkennung; die Board-Historie wird mitgeschrieben. Zurückgelassene
Verweise erkennt der Parser und zählt sie nicht als eigenen Antrag.
This commit is contained in:
2026-09-18 17:32:58 +02:00
parent 6b49b34eef
commit 664a0fd5ee
17 changed files with 1291 additions and 4 deletions
@@ -19,6 +19,12 @@ CREATE TYPE "InactiveReason" AS ENUM ('PLAYER_INACTIVITY', 'REWORKED', 'OTHER');
-- CreateEnum
CREATE TYPE "ProductTarget" AS ENUM ('CC_PACKAGE', 'REDESIGN_PACKAGE', 'IGNORE');
-- CreateEnum
CREATE TYPE "ForumBoard" AS ENUM ('CUSTOM_CHARACTERS', 'AKTIVE_CCS', 'CC_ARCHIV');
-- CreateEnum
CREATE TYPE "ForumClassification" AS ENUM ('NEW_CC', 'REDESIGN', 'REJECTED', 'IGNORE');
-- CreateEnum
CREATE TYPE "ImportStatus" AS ENUM ('PENDING', 'COMMITTED', 'DISCARDED');
@@ -198,6 +204,38 @@ CREATE TABLE "AuditLog" (
CONSTRAINT "AuditLog_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ForumThread" (
"threadId" INTEGER NOT NULL,
"title" TEXT NOT NULL,
"url" TEXT NOT NULL,
"authorName" TEXT,
"authorForumId" INTEGER,
"playerId" INTEGER,
"currentBoard" "ForumBoard" NOT NULL,
"firstSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastSeenAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastBoardChangeAt" TIMESTAMP(3),
"classification" "ForumClassification",
"needsClassification" BOOLEAN NOT NULL DEFAULT true,
"classifiedById" INTEGER,
"classifiedAt" TIMESTAMP(3),
"linkedCharacterId" INTEGER,
"boardChangeNotice" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "ForumThread_pkey" PRIMARY KEY ("threadId")
);
-- CreateTable
CREATE TABLE "ForumThreadBoard" (
"id" SERIAL NOT NULL,
"threadId" INTEGER NOT NULL,
"board" "ForumBoard" NOT NULL,
"observedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "ForumThreadBoard_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
@@ -273,6 +311,18 @@ CREATE INDEX "AuditLog_targetType_targetId_idx" ON "AuditLog"("targetType", "tar
-- CreateIndex
CREATE INDEX "AuditLog_actorUserId_idx" ON "AuditLog"("actorUserId");
-- CreateIndex
CREATE INDEX "ForumThread_needsClassification_idx" ON "ForumThread"("needsClassification");
-- CreateIndex
CREATE INDEX "ForumThread_playerId_idx" ON "ForumThread"("playerId");
-- CreateIndex
CREATE INDEX "ForumThread_currentBoard_idx" ON "ForumThread"("currentBoard");
-- CreateIndex
CREATE INDEX "ForumThreadBoard_threadId_idx" ON "ForumThreadBoard"("threadId");
-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -318,3 +368,12 @@ ALTER TABLE "ImportedOrder" ADD CONSTRAINT "ImportedOrder_playerId_fkey" FOREIGN
-- AddForeignKey
ALTER TABLE "AuditLog" ADD CONSTRAINT "AuditLog_actorUserId_fkey" FOREIGN KEY ("actorUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ForumThread" ADD CONSTRAINT "ForumThread_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ForumThread" ADD CONSTRAINT "ForumThread_linkedCharacterId_fkey" FOREIGN KEY ("linkedCharacterId") REFERENCES "Character"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ForumThreadBoard" ADD CONSTRAINT "ForumThreadBoard_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES "ForumThread"("threadId") ON DELETE CASCADE ON UPDATE CASCADE;
+71 -4
View File
@@ -46,6 +46,19 @@ enum ProductTarget {
IGNORE
}
enum ForumBoard {
CUSTOM_CHARACTERS
AKTIVE_CCS
CC_ARCHIV
}
enum ForumClassification {
NEW_CC
REDESIGN
REJECTED
IGNORE
}
enum ImportStatus {
PENDING
COMMITTED
@@ -101,10 +114,11 @@ model Player {
gextensionUsage Int?
gextensionSyncedAt DateTime?
ledger CreditLedger[]
characters Character[]
orders ImportedOrder[]
unmatched UnmatchedPackage[]
ledger CreditLedger[]
characters Character[]
orders ImportedOrder[]
unmatched UnmatchedPackage[]
forumThreads ForumThread[]
@@index([displayName])
}
@@ -191,6 +205,7 @@ model Character {
successors Character[] @relation("CharacterLineage")
ledgerEntries CreditLedger[]
forumThreads ForumThread[]
createdById Int?
createdBy User? @relation("CharacterCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
@@ -290,3 +305,55 @@ model AuditLog {
@@index([targetType, targetId])
@@index([actorUserId])
}
/// Ein CC-Antrag im Forum. Die Thread-ID bleibt stabil, auch wenn der Thread
/// in ein anderes Board verschoben wird - deshalb ist sie der Schlüssel und
/// nicht die Board-Zugehörigkeit.
model ForumThread {
threadId Int @id
title String
url String
authorName String?
/// Überlebt Namensänderungen im Forum, anders als der Anzeigename.
authorForumId Int?
playerId Int?
player Player? @relation(fields: [playerId], references: [id], onDelete: SetNull)
currentBoard ForumBoard
firstSeenAt DateTime @default(now())
lastSeenAt DateTime @default(now())
lastBoardChangeAt DateTime?
/// Bleibt leer, bis ein Mensch entschieden hat. Es gibt bewusst keine
/// Vorbelegung aus Titel oder Board - beides ist nicht verlässlich genug.
classification ForumClassification?
needsClassification Boolean @default(true)
classifiedById Int?
classifiedAt DateTime?
linkedCharacterId Int?
linkedCharacter Character? @relation(fields: [linkedCharacterId], references: [id], onDelete: SetNull)
/// Ein bereits entschiedener Thread ist in ein anderes Board gewandert.
/// Reine Gedächtnisstütze, löst nie eine Buchung aus.
boardChangeNotice Boolean @default(false)
history ForumThreadBoard[]
@@index([needsClassification])
@@index([playerId])
@@index([currentBoard])
}
/// Wann lag ein Thread in welchem Board. Für Streitfälle nachvollziehbar.
model ForumThreadBoard {
id Int @id @default(autoincrement())
threadId Int
thread ForumThread @relation(fields: [threadId], references: [threadId], onDelete: Cascade)
board ForumBoard
observedAt DateTime @default(now())
@@index([threadId])
}
+2
View File
@@ -18,6 +18,7 @@ import { characterRoutes } from './routes/characters.routes.js';
import { importRoutes } from './routes/imports.routes.js';
import { adminRoutes } from './routes/admin.routes.js';
import { scraperRoutes } from './routes/scraper.routes.js';
import { forumRoutes } from './routes/forum.routes.js';
const here = dirname(fileURLToPath(import.meta.url));
// Im Container liegt das gebaute Frontend neben dem kompilierten Server.
@@ -123,6 +124,7 @@ export async function buildApp(): Promise<FastifyInstance> {
await app.register(importRoutes);
await app.register(adminRoutes);
await app.register(scraperRoutes);
await app.register(forumRoutes);
if (existsSync(webRoot)) {
await app.register(fastifyStatic, {
+4
View File
@@ -31,6 +31,10 @@ const schema = z.object({
// zugeschnitten; eine völlig andere Software ließe sich damit nicht lesen.
GEXTENSION_BASE_URL: z.string().url().default('https://gextension.senseigaming.de'),
// Basis-Adresse des Forums für den Antrags-Abgleich. Der Parser ist auf
// WoltLab (Burning Board) zugeschnitten.
FORUM_BASE_URL: z.string().url().default('https://senseigaming.de/forum'),
// Aufbewahrung der Audit-Einträge in Tagen. 0 schaltet das Aufräumen ab.
// Die Guthaben-Historie ist davon nicht betroffen, die bleibt dauerhaft.
AUDIT_RETENTION_DAYS: z.coerce.number().int().min(0).default(365),
+79
View File
@@ -0,0 +1,79 @@
/**
* Liest Thread-Listen eines WoltLab-Forums (Burning Board).
*
* Gelesen wird ausschließlich die Übersichtsseite: sie enthält neben Titel und
* Thread-ID auch den Ersteller, sodass die Threads nicht einzeln geöffnet
* werden müssen. Das hält einen Lauf bei drei Anfragen statt einer je Thread.
*
* Wichtig: Eine Boardseite enthält neben der Thread-Liste auch Unterforen und
* globale Kästen ("letzte Beiträge"). Beides trägt ebenfalls Thread-Links, ist
* aber kein Thread dieses Boards - deshalb wird strikt entlang der
* tabularListRow-Einträge gelesen und nicht über alle Links im Dokument.
*/
export interface ForumThread {
threadId: number;
title: string;
url: string;
authorName: string | null;
/// Stabiler als der Name: Forumsnamen ändern sich, die ID nicht.
authorForumId: number | null;
/// WoltLab lässt beim Verschieben optional einen Verweis am alten Ort zurück.
isMovedStub: boolean;
}
const ROW_SPLIT = /<li class="tabularListRow">/;
const TOPIC_LINK =
/<a\s+href="([^"]*thread\/(\d+)-[^"]*)"[^>]*class="[^"]*wbbTopicLink[^"]*"[^>]*>\s*([^<]{1,200})/;
const USER_LINK =
/<a\s+href="[^"]*user\/(\d+)-[^"]*"[^>]*class="userLink"[^>]*>(?:<i[^>]*><\/i>)?\s*(?:<span[^>]*>)?\s*([^<]{1,80})/;
// Ein zurückgelassener Verweis ist kein eigener Thread.
const MOVED_MARKER = /wbbTopicLinkMoved|class="[^"]*movedTopic|>\s*Verschoben\s*</i;
function decode(value: string): string {
return value
.replace(/&quot;/g, '"')
.replace(/&#0?39;/g, "'")
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&nbsp;/g, ' ')
.replace(/\s+/g, ' ')
.trim();
}
export function parseBoard(html: string): ForumThread[] {
const threads: ForumThread[] = [];
const seen = new Set<number>();
for (const block of html.split(ROW_SPLIT).slice(1)) {
// Nur bis zum Ende der Zeile schauen, sonst greift der nächste Eintrag rein.
const topic = TOPIC_LINK.exec(block);
if (!topic) continue;
const threadId = Number(topic[2]);
if (!Number.isInteger(threadId) || seen.has(threadId)) continue;
seen.add(threadId);
const user = USER_LINK.exec(block);
threads.push({
threadId,
title: decode(topic[3] ?? ''),
url: decode(topic[1] ?? ''),
authorName: user ? decode(user[2] ?? '') || null : null,
authorForumId: user ? Number(user[1]) : null,
isMovedStub: MOVED_MARKER.test(block),
});
}
return threads;
}
/** Höchste Seitenzahl der Blätterleiste, mindestens 1. */
export function parsePageCount(html: string): number {
const numbers = [...html.matchAll(/pageNo=(\d+)/g)].map((m) => Number(m[1]));
return numbers.length > 0 ? Math.max(1, ...numbers) : 1;
}
+74
View File
@@ -0,0 +1,74 @@
import type { FastifyInstance } from 'fastify';
import { z } from 'zod';
import { ForumBoard, ForumClassification } from '@prisma/client';
import { requireAdmin, requireAuth } from '../auth/guard.js';
import {
assignPlayer,
classifyThread,
dismissBoardChangeNotice,
listBoardChangeNotices,
listThreads,
scanForum,
} from '../services/forum.js';
import { contextOf, idParam, parseWith } from './helpers.js';
export async function forumRoutes(app: FastifyInstance): Promise<void> {
app.post('/api/forum/scan', { preHandler: requireAdmin }, async (request) => {
return scanForum(contextOf(request));
});
app.get('/api/forum/threads', { preHandler: requireAuth }, async (request) => {
const query = parseWith(
z.object({
open: z.enum(['true', 'false']).default('true'),
playerId: z.coerce.number().int().positive().optional(),
board: z.nativeEnum(ForumBoard).optional(),
}),
request.query,
);
return {
items: await listThreads({
onlyOpen: query.open === 'true',
...(query.playerId !== undefined ? { playerId: query.playerId } : {}),
...(query.board ? { board: query.board } : {}),
}),
};
});
app.get('/api/forum/notices', { preHandler: requireAuth }, async () => {
return { items: await listBoardChangeNotices() };
});
app.post('/api/forum/threads/:id/dismiss', { preHandler: requireAdmin }, async (request) => {
const { id } = parseWith(idParam, request.params);
await dismissBoardChangeNotice(id, contextOf(request));
return { ok: true };
});
app.post('/api/forum/threads/:id/player', { preHandler: requireAdmin }, async (request) => {
const { id } = parseWith(idParam, request.params);
const body = parseWith(
z.object({ playerId: z.number().int().positive() }),
request.body,
);
await assignPlayer(id, body.playerId, contextOf(request));
return { ok: true };
});
app.post('/api/forum/threads/:id/classify', { preHandler: requireAdmin }, async (request) => {
const { id } = parseWith(idParam, request.params);
const body = parseWith(
z.object({
classification: z.nativeEnum(ForumClassification),
characterName: z.string().trim().min(1).max(160).optional(),
loreText: z.string().trim().max(5000).optional(),
predecessorId: z.number().int().positive().optional(),
useKind: z.enum(['REDESIGN_PAID', 'REDESIGN_KULANZ']).optional(),
}),
request.body,
);
return classifyThread(id, body, contextOf(request));
});
}
+354
View File
@@ -0,0 +1,354 @@
import { ForumBoard, ForumClassification, type Prisma } from '@prisma/client';
import { prisma } from '../db.js';
import { env } from '../env.js';
import { badRequest, conflict, notFound } from '../errors.js';
import { parseBoard, parsePageCount, type ForumThread } from '../lib/forum.js';
import { recordAudit, type ActionContext } from './audit.js';
/// Die drei Boards, zwischen denen ein Antrag wandert. Board 66 enthält neben
/// Unterforen auch eigene Threads, deshalb wird es mitgelesen.
export const BOARDS: { board: ForumBoard; path: string }[] = [
{ board: ForumBoard.CUSTOM_CHARACTERS, path: 'board/66-custom-characters' },
{ board: ForumBoard.AKTIVE_CCS, path: 'board/355-aktive-ccs' },
{ board: ForumBoard.CC_ARCHIV, path: 'board/113-cc-archiv' },
];
const MIN_REQUEST_GAP_MS = 1000;
const MAX_PAGES_PER_BOARD = 20;
let lastRequestAt = 0;
async function throttle(): Promise<void> {
const wait = lastRequestAt + MIN_REQUEST_GAP_MS - Date.now();
if (wait > 0) await new Promise((resolve) => setTimeout(resolve, wait));
lastRequestAt = Date.now();
}
async function fetchPage(path: string, page: number): Promise<string> {
await throttle();
const base = env.FORUM_BASE_URL.replace(/\/+$/, '');
const url = page > 1 ? `${base}/index.php?${path}/&pageNo=${page}` : `${base}/index.php?${path}/`;
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 20000);
try {
const response = await fetch(url, {
signal: controller.signal,
headers: {
'user-agent': 'CC-Manager/1.0 (Antrags-Abgleich für das CC-Team)',
accept: 'text/html',
},
});
if (!response.ok) {
throw badRequest('BOARD_UNAVAILABLE', `Board nicht abrufbar (HTTP ${response.status})`);
}
return await response.text();
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
throw badRequest('BOARD_TIMEOUT', 'Zeitüberschreitung beim Abruf des Boards');
}
throw error;
} finally {
clearTimeout(timer);
}
}
export interface ForumScanSummary {
scannedBoards: number;
scannedPages: number;
newThreads: number;
movedThreads: number;
boardChangeNotices: number;
skippedStubs: number;
matchedPlayers: number;
withoutPlayer: number;
failedBoards: { board: string; reason: string }[];
}
/**
* Liest die Boards und schreibt gefundene Threads fort. Klassifiziert wird
* bewusst nichts: weder Titel noch Board sind verlässlich genug, um daraus
* eine Buchung abzuleiten. Jeder neue Thread wartet auf eine Entscheidung.
*/
export async function scanForum(ctx: ActionContext): Promise<ForumScanSummary> {
const summary: ForumScanSummary = {
scannedBoards: 0,
scannedPages: 0,
newThreads: 0,
movedThreads: 0,
boardChangeNotices: 0,
skippedStubs: 0,
matchedPlayers: 0,
withoutPlayer: 0,
failedBoards: [],
};
// Forumsnamen einmal laden statt je Thread zu suchen.
const players = await prisma.player.findMany({
where: { forumName: { not: null } },
select: { id: true, forumName: true },
});
const byForumName = new Map(players.map((p) => [(p.forumName as string).toLowerCase(), p.id]));
for (const { board, path } of BOARDS) {
let threads: ForumThread[] = [];
try {
const first = await fetchPage(path, 1);
summary.scannedPages += 1;
threads = parseBoard(first);
const pages = Math.min(parsePageCount(first), MAX_PAGES_PER_BOARD);
for (let page = 2; page <= pages; page += 1) {
const html = await fetchPage(path, page);
summary.scannedPages += 1;
threads.push(...parseBoard(html));
}
summary.scannedBoards += 1;
} catch (error) {
summary.failedBoards.push({
board: path,
reason: error instanceof Error ? error.message : 'Unbekannter Fehler',
});
continue;
}
for (const thread of threads) {
// Ein zurückgelassener Verweis ist kein eigener Antrag.
if (thread.isMovedStub) {
summary.skippedStubs += 1;
continue;
}
const playerId = thread.authorName
? byForumName.get(thread.authorName.toLowerCase()) ?? null
: null;
const existing = await prisma.forumThread.findUnique({
where: { threadId: thread.threadId },
});
if (!existing) {
await prisma.forumThread.create({
data: {
threadId: thread.threadId,
title: thread.title,
url: thread.url,
authorName: thread.authorName,
authorForumId: thread.authorForumId,
playerId,
currentBoard: board,
history: { create: [{ board }] },
},
});
summary.newThreads += 1;
if (playerId) summary.matchedPlayers += 1;
else summary.withoutPlayer += 1;
continue;
}
const movedBoard = existing.currentBoard !== board;
await prisma.forumThread.update({
where: { threadId: thread.threadId },
data: {
title: thread.title,
url: thread.url,
authorName: thread.authorName,
authorForumId: thread.authorForumId,
lastSeenAt: new Date(),
// Eine später nachgetragene Zuordnung nicht wieder überschreiben.
...(existing.playerId === null && playerId !== null ? { playerId } : {}),
...(movedBoard
? {
currentBoard: board,
lastBoardChangeAt: new Date(),
// Wandert ein bereits entschiedener Thread, ist das ein Hinweis
// für den Admin - nie eine automatische Statusänderung.
...(existing.classification !== null ? { boardChangeNotice: true } : {}),
}
: {}),
},
});
if (movedBoard) {
await prisma.forumThreadBoard.create({ data: { threadId: thread.threadId, board } });
summary.movedThreads += 1;
if (existing.classification !== null) summary.boardChangeNotices += 1;
}
}
}
await recordAudit(prisma, ctx, {
action: 'forum.scan',
targetType: 'forum',
targetId: null,
details: { ...summary } as unknown as Prisma.InputJsonValue,
});
return summary;
}
export async function listThreads(options: {
onlyOpen?: boolean;
playerId?: number;
board?: ForumBoard;
}) {
return prisma.forumThread.findMany({
where: {
...(options.onlyOpen ? { needsClassification: true } : {}),
...(options.playerId !== undefined ? { playerId: options.playerId } : {}),
...(options.board ? { currentBoard: options.board } : {}),
},
orderBy: [{ lastSeenAt: 'desc' }, { threadId: 'desc' }],
include: {
player: { select: { id: true, displayName: true } },
linkedCharacter: { select: { id: true, name: true } },
},
});
}
/** Threads, bei denen nach der Entscheidung das Board gewechselt hat. */
export async function listBoardChangeNotices() {
return prisma.forumThread.findMany({
where: { boardChangeNotice: true },
orderBy: { lastBoardChangeAt: 'desc' },
include: {
player: { select: { id: true, displayName: true } },
linkedCharacter: { select: { id: true, name: true, status: true } },
},
});
}
export async function dismissBoardChangeNotice(threadId: number, ctx: ActionContext): Promise<void> {
const thread = await prisma.forumThread.findUnique({ where: { threadId } });
if (!thread) throw notFound('Thread');
await prisma.forumThread.update({
where: { threadId },
data: { boardChangeNotice: false },
});
await recordAudit(prisma, ctx, {
action: 'forum.notice_dismissed',
targetType: 'forum_thread',
targetId: threadId,
details: { title: thread.title, board: thread.currentBoard },
});
}
/** Ordnet einen Thread nachträglich einem Spieler zu. */
export async function assignPlayer(
threadId: number,
playerId: number,
ctx: ActionContext,
): Promise<void> {
const [thread, player] = await Promise.all([
prisma.forumThread.findUnique({ where: { threadId } }),
prisma.player.findUnique({ where: { id: playerId }, select: { id: true } }),
]);
if (!thread) throw notFound('Thread');
if (!player) throw notFound('Spieler');
await prisma.forumThread.update({ where: { threadId }, data: { playerId } });
await recordAudit(prisma, ctx, {
action: 'forum.player_assigned',
targetType: 'forum_thread',
targetId: threadId,
details: { title: thread.title, playerId },
});
}
export interface ClassifyInput {
classification: ForumClassification;
/// Nur bei NEW_CC und REDESIGN.
characterName?: string;
loreText?: string;
/// Nur bei REDESIGN: welcher CC wurde ersetzt und womit bezahlt.
predecessorId?: number;
useKind?: 'REDESIGN_PAID' | 'REDESIGN_KULANZ';
}
/**
* Entscheidet über einen Antrag. Angenommene Anträge laufen durch dieselben
* Aktionen wie eine Eingabe von Hand - es gibt keinen zweiten Buchungsweg,
* der andere Regeln anwenden könnte.
*/
export async function classifyThread(
threadId: number,
input: ClassifyInput,
ctx: ActionContext,
): Promise<{ characterId: number | null }> {
const thread = await prisma.forumThread.findUnique({ where: { threadId } });
if (!thread) throw notFound('Thread');
if (thread.classification !== null) {
throw conflict('ALREADY_CLASSIFIED', 'Dieser Antrag wurde bereits entschieden');
}
let characterId: number | null = null;
if (
input.classification === ForumClassification.NEW_CC ||
input.classification === ForumClassification.REDESIGN
) {
if (thread.playerId === null) {
throw badRequest('NO_PLAYER', 'Dem Antrag ist kein Spieler zugeordnet');
}
const name = input.characterName?.trim();
if (!name) throw badRequest('NO_NAME', 'Für den CC wird ein Name gebraucht');
const { createCharacter, redesignCharacter } = await import('./characters.js');
const note = `Forum-Antrag #${threadId}: ${thread.title}`;
if (input.classification === ForumClassification.NEW_CC) {
const result = await createCharacter(
thread.playerId,
{ name, loreText: input.loreText, note },
ctx,
);
characterId = result.character.id;
} else {
if (input.predecessorId === undefined) {
throw badRequest('NO_PREDECESSOR', 'Bitte angeben, welcher CC redesignt wurde');
}
const result = await redesignCharacter(
input.predecessorId,
{
name,
loreText: input.loreText,
useKind: input.useKind ?? 'REDESIGN_KULANZ',
note,
},
ctx,
);
characterId = result.character.id;
}
}
await prisma.forumThread.update({
where: { threadId },
data: {
classification: input.classification,
needsClassification: false,
classifiedById: ctx.actorId,
classifiedAt: new Date(),
linkedCharacterId: characterId,
},
});
await recordAudit(prisma, ctx, {
action: 'forum.classified',
targetType: 'forum_thread',
targetId: threadId,
details: {
title: thread.title,
classification: input.classification,
playerId: thread.playerId,
characterId,
},
});
return { characterId };
}
+50
View File
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<!-- Nachbau einer WoltLab-Boardübersicht mit erfundenen Daten.
Die echte Seite baut die Thread-Liste genauso auf. -->
<html lang="de"><body>
<div class="wbbBoardNode">
<div class="wbbBoardNode__title"><a href="https://forum.example.org/index.php?board/99-unterforum/">Ein Unterforum</a></div>
<div class="wbbBoardNode__lastPost">
<a href="https://forum.example.org/index.php?thread/9999-letzter-beitrag-im-unterforum/" class="wbbBoardNode__lastPostLink wbbTopicLink" data-object-id="9999">Letzter Beitrag im Unterforum</a>
</div>
</div>
<ol class="tabularList wbbTopicList">
<li class="tabularListRow">
<ul class="tabularListColumns">
<li class="columnIcon columnAvatar">
<a href="https://forum.example.org/index.php?user/501-antragsteller/" data-object-id="501" class="userLink"><i class="sl"></i><span style="color: #333;">Antragsteller</span></a>
</li>
<li class="columnSubject">
<a href="https://forum.example.org/index.php?thread/7001-cc-antrag-testfigur/" class="messageGroupLink wbbTopicLink" data-object-id="7001">CC Antrag | Testfigur</a>
</li>
</ul>
</li>
<li class="tabularListRow">
<ul class="tabularListColumns">
<li class="columnIcon columnAvatar">
<a href="https://forum.example.org/index.php?user/502-zweiter-nutzer/" data-object-id="502" class="userLink"><span>Zweiter Nutzer</span></a>
</li>
<li class="columnSubject">
<a href="https://forum.example.org/index.php?thread/7002-custom-character-redesign-alt/" class="messageGroupLink wbbTopicLink" data-object-id="7002">Custom Character Redesign | Alt zu Neu</a>
</li>
</ul>
</li>
<li class="tabularListRow">
<ul class="tabularListColumns">
<li class="columnIcon columnAvatar">
<a href="https://forum.example.org/index.php?user/501-antragsteller/" data-object-id="501" class="userLink"><span>Antragsteller</span></a>
</li>
<li class="columnSubject">
<span class="badge label green">Verschoben</span>
<a href="https://forum.example.org/index.php?thread/7003-verschobener-thread/" class="messageGroupLink wbbTopicLink wbbTopicLinkMoved" data-object-id="7003">Ein verschobener Thread</a>
</li>
</ul>
</li>
</ol>
<nav class="pagination"><ul>
<li><a href="index.php?board/66-custom-characters/&amp;pageNo=2" class="pageNavigationLink">2</a></li>
<li><a href="index.php?board/66-custom-characters/&amp;pageNo=3" class="pageNavigationLink">3</a></li>
</ul></nav>
</body></html>
+51
View File
@@ -0,0 +1,51 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, it } from 'node:test';
import { parseBoard, parsePageCount } from '../src/lib/forum.js';
const here = dirname(fileURLToPath(import.meta.url));
const BOARD = readFileSync(join(here, 'fixtures', 'board.html'), 'utf8');
describe('Board-Übersicht lesen', () => {
const threads = parseBoard(BOARD);
it('liest die Threads der Liste', () => {
assert.equal(threads.length, 3);
assert.deepEqual(
threads.map((t) => t.threadId),
[7001, 7002, 7003],
);
});
it('nimmt den Ersteller aus der Übersicht, nicht den letzten Antwortenden', () => {
const first = threads.find((t) => t.threadId === 7001);
assert.equal(first?.authorName, 'Antragsteller');
assert.equal(first?.authorForumId, 501, 'die Forum-ID überlebt Namensänderungen');
});
it('löst Umlaut- und Anführungszeichen-Entities auf', () => {
const second = threads.find((t) => t.threadId === 7002);
assert.equal(second?.title, 'Custom Character Redesign | Alt zu Neu');
});
it('erkennt einen zurückgelassenen Verweis als solchen', () => {
const stub = threads.find((t) => t.threadId === 7003);
assert.equal(stub?.isMovedStub, true);
});
it('ignoriert Unterforen und deren letzte Beiträge', () => {
// 9999 steht im wbbBoardNode-Kasten, gehoert aber nicht in dieses Board.
assert.equal(threads.some((t) => t.threadId === 9999), false);
});
it('liest die Seitenzahl aus der Blätterleiste', () => {
assert.equal(parsePageCount(BOARD), 3);
assert.equal(parsePageCount('<html>ohne Blaetterleiste</html>'), 1);
});
it('kommt mit einer leeren Seite klar', () => {
assert.deepEqual(parseBoard('<html><body>nichts</body></html>'), []);
});
});