Cookie'ler saatler içinde eskiyordu, her seferinde manuel Coolify env güncellemesi + redeploy gerekiyordu. Artık DB'de (app_settings tablosu) tutuluyor; /settings sayfasından yeni cookies.txt yapıştırılıp kaydedilebiliyor, bir sonraki yt-dlp çağrısında redeploy gerekmeden devreye giriyor. YTDLP_COOKIES_B64 env var mekanizması kaldırıldı. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
"use server";
|
||
|
||
import { unlink } from "node:fs/promises";
|
||
import { prisma } from "@streamclipper/db";
|
||
import { revalidatePath } from "next/cache";
|
||
|
||
export async function addChannel(formData: FormData) {
|
||
const name = String(formData.get("name") ?? "").trim();
|
||
const youtubeHandle = String(formData.get("youtubeHandle") ?? "").trim();
|
||
const channelId = String(formData.get("channelId") ?? "").trim();
|
||
|
||
if (!name || !youtubeHandle || !channelId) {
|
||
throw new Error("Kanal adı, handle ve channel_id alanları zorunlu.");
|
||
}
|
||
|
||
await prisma.channel.create({
|
||
data: { name, youtubeHandle, channelId, isActive: true },
|
||
});
|
||
|
||
revalidatePath("/");
|
||
}
|
||
|
||
export async function deleteRawSegment(segmentId: string) {
|
||
const segment = await prisma.rawSegment.findUnique({ where: { id: segmentId } });
|
||
if (!segment) return;
|
||
|
||
await prisma.candidateSegment.deleteMany({ where: { rawSegmentId: segmentId } });
|
||
await prisma.rawSegment.delete({ where: { id: segmentId } });
|
||
await unlink(segment.filePath).catch(() => {});
|
||
|
||
revalidatePath("/segments");
|
||
revalidatePath("/", "layout");
|
||
}
|
||
|
||
export async function deleteCandidateSegment(candidateId: string) {
|
||
await prisma.candidateSegment.delete({ where: { id: candidateId } });
|
||
|
||
revalidatePath("/segments");
|
||
revalidatePath("/", "layout");
|
||
}
|
||
|
||
export async function updateYtdlpCookies(formData: FormData) {
|
||
const value = String(formData.get("cookies") ?? "").trim();
|
||
|
||
if (!value) {
|
||
throw new Error("Cookie içeriği boş olamaz.");
|
||
}
|
||
|
||
await prisma.appSetting.upsert({
|
||
where: { key: "ytdlp_cookies" },
|
||
create: { key: "ytdlp_cookies", value },
|
||
update: { value },
|
||
});
|
||
|
||
revalidatePath("/settings");
|
||
}
|