"use server"; // File blocks, from the console. import { revalidatePath } from "next/cache"; import { api, unwrap } from "@/lib/api"; import { attempt, field, type ActionState } from "@/lib/actions"; const done = (sha256: string) => { revalidatePath("/console/blocks"); revalidatePath(`/console/blocks/${sha256}`); revalidatePath("/console/products"); }; /** Blocks a file network-wide, removing the products using it. */ export async function blockFile(_: ActionState, form: FormData): Promise { const sha256 = field(form, "sha256"); return attempt(async () => { const { removed } = unwrap(await api.blocks({ sha256 }).put({ reason: field(form, "reason") })); done(sha256); return removed.length ? `Blocked. Removed ${removed.length === 1 ? "1 product" : `${removed.length} products`}.` : "Blocked."; }); } /** Unblocks a file. The products it removed stay removed. */ export async function unblockFile(_: ActionState, form: FormData): Promise { const sha256 = field(form, "sha256"); return attempt(async () => { unwrap(await api.blocks({ sha256 }).delete({ reason: field(form, "reason") })); done(sha256); return "Unblocked."; }); }