mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-09-21 13:31:42 +00:00
feat: Docker audit + Telegram bot service + send UI
Docker:
- Harden docker-compose.yml: parameterized DB creds, required AUTH_SECRET,
health checks, resource limits, network isolation, removed exposed DB port
- Add profiles (telegram/bot/full) so base 'docker compose up' needs only AUTH_SECRET
- Fix docker-entrypoint.sh: AUTH_SECRET startup guard
- Fix Dockerfile: copy prisma.config.ts + dotenv into production image
- Update .env.example with all new variables
- Update .dockerignore
Telegram Bot Service (bot/):
- TDLib-based bot using bot token auth (not HTTP Bot API)
- Commands: /search, /latest, /package, /link, /unlink, /subscribe, /unsubscribe
- pg_notify listener for send requests (bot_send) and new packages (new_package)
- Subscription-based notifications when matching packages arrive
- Dockerfile with multi-stage build (bookworm-slim for glibc/TDLib)
API & Database:
- Prisma: TelegramLink, BotSendRequest, BotSubscription models + migration
- POST /api/telegram/bot/send - queue package delivery to linked TG account
- GET /api/telegram/bot/send/[id] - poll send request status
- Server actions: generateTelegramLinkCode, unlinkTelegram, getBotSendHistory
- Worker: emit pg_notify('new_package') after creating packages
Frontend:
- Settings: TelegramLinkCard for account linking via one-time code
- STL table + drawer: SendToTelegramButton with send dialog and status polling
- Telegram admin: Bot Sends tab with delivery history table
- Shared SendHistoryRow type
README: Updated with bot docs, profiles, config vars, project structure
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* GET /api/telegram/bot/send/[id]
|
||||
* Poll the status of a bot send request.
|
||||
*/
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
const sendRequest = await prisma.botSendRequest.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
error: true,
|
||||
requestedByUserId: true,
|
||||
createdAt: true,
|
||||
completedAt: true,
|
||||
package: { select: { id: true, fileName: true } },
|
||||
telegramLink: { select: { userId: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!sendRequest) {
|
||||
return NextResponse.json({ error: "Send request not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Users can only see their own requests unless admin
|
||||
const isOwner =
|
||||
sendRequest.requestedByUserId === session.user.id ||
|
||||
sendRequest.telegramLink.userId === session.user.id;
|
||||
|
||||
if (!isOwner && session.user.role !== "ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: sendRequest.id,
|
||||
status: sendRequest.status,
|
||||
error: sendRequest.error,
|
||||
packageId: sendRequest.package.id,
|
||||
fileName: sendRequest.package.fileName,
|
||||
createdAt: sendRequest.createdAt,
|
||||
completedAt: sendRequest.completedAt,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user