diff --git a/apps/frontend/app/actions.ts b/apps/frontend/app/actions.ts index be73c4c..11f8ce5 100644 --- a/apps/frontend/app/actions.ts +++ b/apps/frontend/app/actions.ts @@ -3,6 +3,7 @@ import { unlink } from "node:fs/promises"; import { prisma } from "@streamclipper/db"; import { revalidatePath } from "next/cache"; +import { redirect } from "next/navigation"; export async function addChannel(formData: FormData) { const name = String(formData.get("name") ?? "").trim(); @@ -39,6 +40,25 @@ export async function deleteCandidateSegment(candidateId: string) { revalidatePath("/", "layout"); } +export async function deleteChannel(channelId: string) { + const sessions = await prisma.streamSession.findMany({ + where: { channelId }, + include: { segments: true }, + }); + const rawSegmentIds = sessions.flatMap((s) => s.segments.map((seg) => seg.id)); + const filePaths = sessions.flatMap((s) => s.segments.map((seg) => seg.filePath)); + + await prisma.candidateSegment.deleteMany({ where: { rawSegmentId: { in: rawSegmentIds } } }); + await prisma.rawSegment.deleteMany({ where: { sessionId: { in: sessions.map((s) => s.id) } } }); + await prisma.streamSession.deleteMany({ where: { channelId } }); + await prisma.channel.delete({ where: { id: channelId } }); + + await Promise.all(filePaths.map((p) => unlink(p).catch(() => {}))); + + revalidatePath("/", "layout"); + redirect("/"); +} + export async function updateYtdlpCookies(formData: FormData) { const value = String(formData.get("cookies") ?? "").trim(); diff --git a/apps/frontend/app/channels/[id]/page.tsx b/apps/frontend/app/channels/[id]/page.tsx index ec298ad..09b0970 100644 --- a/apps/frontend/app/channels/[id]/page.tsx +++ b/apps/frontend/app/channels/[id]/page.tsx @@ -2,7 +2,7 @@ import { notFound } from "next/navigation"; import Link from "next/link"; import { prisma } from "@streamclipper/db"; import { fetchChannelStatuses } from "../../../lib/apiDaemon"; -import { deleteRawSegment, deleteCandidateSegment } from "../../actions"; +import { deleteRawSegment, deleteCandidateSegment, deleteChannel } from "../../actions"; import { DeleteButton } from "../../components/DeleteButton"; export const dynamic = "force-dynamic"; @@ -51,7 +51,12 @@ export default async function ChannelDetailPage({ params }: { params: Promise<{ <>
← Kanal Durumu
-{channel.youtubeHandle} · {channel.channelId}