feat: add API endpoint for syncing selected channel backlog

This commit is contained in:
MythEclipse
2026-05-14 04:02:25 +07:00
parent d5977c8845
commit 5aa57f884f
2 changed files with 65 additions and 115 deletions
+27
View File
@@ -12,6 +12,7 @@ import { discordPlayer } from "./player";
import type { VoiceController } from "./voiceController";
import { getDatabase, getPersistedValue, setPersistedValue } from "./muxer-queue";
import { getMessagesByChannel, getAttachmentsByChannel } from "./moderation/messageStore";
import { syncSelectedChannelBacklog } from "./moderation/backlogSync";
const wsLogger = createChildLogger("webserver");
@@ -277,6 +278,32 @@ export function startWebserver(
}
});
app.post("/api/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,
);
}
const count = await syncSelectedChannelBacklog(_client, getDatabase(), guildId, channelId);
res.json({
success: true,
channelId,
messagesSync: count,
});
} catch (error) {
next(error);
}
});
// Inbound: Discord PCM → tagged chunks → browser
(global as any).broadcastPcmToWeb = (chunk: Buffer, userId: string) => {
let hash = 0;