mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { auth } from "@/lib/auth";
|
|
import { redirect } from "next/navigation";
|
|
import { listAccounts, listChannels, getGlobalDestination } from "@/lib/telegram/admin-queries";
|
|
import { getIngestionStatus } from "@/lib/telegram/queries";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { TelegramAdmin } from "./_components/telegram-admin";
|
|
|
|
export default async function TelegramPage() {
|
|
const session = await auth();
|
|
if (!session?.user?.id) redirect("/login");
|
|
if (session.user.role !== "ADMIN") redirect("/dashboard");
|
|
|
|
const [accounts, channels, ingestionStatus, globalDestination, sendHistory] = await Promise.all([
|
|
listAccounts(),
|
|
listChannels(),
|
|
getIngestionStatus(),
|
|
getGlobalDestination(),
|
|
prisma.botSendRequest.findMany({
|
|
orderBy: { createdAt: "desc" },
|
|
take: 50,
|
|
include: {
|
|
package: { select: { fileName: true } },
|
|
telegramLink: { select: { telegramName: true } },
|
|
},
|
|
}),
|
|
]);
|
|
|
|
const serializedHistory = sendHistory.map((r: typeof sendHistory[number]) => ({
|
|
id: r.id,
|
|
packageName: r.package.fileName,
|
|
recipientName: r.telegramLink.telegramName,
|
|
status: r.status,
|
|
error: r.error,
|
|
createdAt: r.createdAt.toISOString(),
|
|
completedAt: r.completedAt?.toISOString() ?? null,
|
|
}));
|
|
|
|
return (
|
|
<TelegramAdmin
|
|
accounts={accounts}
|
|
channels={channels}
|
|
ingestionStatus={ingestionStatus}
|
|
globalDestination={globalDestination}
|
|
sendHistory={serializedHistory}
|
|
workerIntervalMinutes={parseInt(process.env.WORKER_INTERVAL_MINUTES ?? "60", 10)}
|
|
/>
|
|
);
|
|
}
|