refactor: split api routes by concern

This commit is contained in:
MythEclipse
2026-05-14 19:46:47 +07:00
parent 3fb1fcb72c
commit c81a499535
7 changed files with 503 additions and 207 deletions
+53
View File
@@ -0,0 +1,53 @@
import type { Client } from "discord.js-selfbot-v13";
import type { Router } from "express";
import express from "express";
import { AppError } from "../errors";
import { createChildLogger } from "../logger";
import { syncSelectedChannelBacklog } from "../moderation/backlogSync";
const logger = createChildLogger("sync-routes");
export function createSyncRoutes(client: Client): Router {
const router = express.Router();
// POST /api/backlog-sync - Sync message backlog for a channel
router.post("/backlog-sync", async (req, res, next) => {
try {
const { guildId, channelId } = req.body as {
guildId?: string;
channelId?: string;
};
if (!guildId || !channelId) {
throw new AppError(
"guildId and channelId are required",
"MISSING_BACKLOG_PARAMS",
400,
);
}
logger.info({ guildId, channelId }, "Starting backlog sync");
const count = await syncSelectedChannelBacklog(
client,
guildId,
channelId,
);
logger.info(
{ guildId, channelId, messagesSync: count },
"Backlog sync complete",
);
res.json({
success: true,
channelId,
messagesSync: count,
});
} catch (error) {
next(error);
}
});
return router;
}