feat(config): add API route for app configuration and update related logic for monitor guild

This commit is contained in:
MythEclipse
2026-06-01 11:16:07 +07:00
parent 49e9197ce0
commit 8310e58239
10 changed files with 154 additions and 32 deletions
+16
View File
@@ -1,5 +1,6 @@
import type { Router } from "express";
import express from "express";
import { config } from "../config.js";
import { AppError } from "../errors.js";
import {
getAnalysisQueueStatus,
@@ -7,6 +8,7 @@ import {
} from "../moderation/aiAnalyzer.js";
import {
searchMessages,
getMessageById,
updateMessageAIAnalysis,
} from "../moderation/messageStore.js";
import type { MessageRecord } from "../moderation/types.js";
@@ -49,6 +51,7 @@ export function createAnalysisRoutes(): Router {
const results = await searchMessages({
query: q,
guildId: config.MONITOR_GUILD_ID,
channelId,
limit: limitNum,
});
@@ -78,6 +81,19 @@ export function createAnalysisRoutes(): Router {
throw new AppError("Message ID is required", "MISSING_MESSAGE_ID", 400);
}
const existing = await getMessageById(id);
if (!existing) {
throw new AppError("Message not found", "MESSAGE_NOT_FOUND", 404);
}
if (existing.guild_id !== config.MONITOR_GUILD_ID) {
throw new AppError(
"Message is outside the monitor guild",
"INVALID_GUILD",
403,
);
}
// P3: Single UPDATE + RETURNING instead of GET + UPDATE + GET
const updated = await updateMessageAIAnalysis(id, {
status: "pending",