"use server"; // «Gitea» (PEP-280): the superadmin closes one public repository at a time. import { PeppaError, requireSuperadmin } from "@peppa/core"; import { makeRepoPrivate } from "@peppa/runner"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { asWebActor, requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; const str = (f: FormData, k: string) => String(f.get(k) ?? "").trim(); /** «Сделать закрытым»: back to the same list with what was closed, or the reason it was not. */ export async function makeRepoPrivateAction(f: FormData) { const user = asWebActor(await requireUser()); const back = new URLSearchParams(); for (const k of ["q", "show"]) if (str(f, k)) back.set(k, str(f, k)); try { await requireSuperadmin(db, user); const r = await makeRepoPrivate(db, user, str(f, "repo")); back.set("closed", r.fullName); // The list is cached (PEP-273): without a fresh one the repository would still show as public for a minute. back.set("fresh", "1"); } catch (e) { const t = await getT(); const msg = e instanceof PeppaError ? t.text(e.message) : t("Ошибка: {message}", { message: (e as Error).message }); back.set("error", msg.slice(0, 300)); } revalidatePath("/gitea"); redirect(`/gitea${back.size ? `?${back}` : ""}`); }