"use server"; // Recorded grants from the console (docs/imports.md): admins record consent for IMVU creators who won't make an // account, prove it with a tagline code, and change or withdraw them until the creator claims them. import { revalidatePath } from "next/cache"; import { api, ApiError, unwrap } from "@/lib/api"; import { attempt, field, type ActionState } from "@/lib/actions"; import { productIDs } from "@/lib/imvu"; const done = () => revalidatePath("/console/imports"); /** Records a creator's consent: a grant for an unclaimed creator standing in for their IMVU account. */ export async function recordGrant(_: ActionState, form: FormData): Promise { const scope = field(form, "scope") === "products" ? "products" : "shop"; const list = productIDs(field(form, scope === "products" ? "products" : "exclude")); if (!list) return { error: "Products are IMVU product IDs or shop links, separated by spaces, commas or lines." }; return attempt(async () => { const r = unwrap( await api.console.imports.grants.post({ catalog: field(form, "catalog"), imvu: field(form, "imvu"), scope, ...(scope === "products" ? { products: list } : { exclude: list }), listed: form.get("listed") === "on", evidence: field(form, "evidence"), }), ); done(); return `Recorded for ${r.grant.imvuName}. The catalog's team accepts it before anything is imported.`; }); } /** Proof without an account: a code for the creator's tagline, then checking it. */ export async function grantProof(_: ActionState, form: FormData): Promise { const id = field(form, "id"); return attempt(async () => { if (field(form, "intent") === "check") { unwrap(await api.console.imports.grants({ id }).proof.check.post()); done(); return "Proven: the code is in their tagline. They can take it out now."; } const { code } = unwrap(await api.console.imports.grants({ id }).proof.post()); done(); return `Send them this code to put in their IMVU tagline: ${code}`; }); } /** Changes what a recorded grant covers, or withdraws it. */ export async function changeRecorded(_: ActionState, form: FormData): Promise { const id = field(form, "id"); return attempt(async () => { if (field(form, "intent") === "withdraw") { const reason = field(form, "reason") || "Withdrawn at the creator's request."; const r = unwrap(await api.imports.grants({ id }).delete({ reason })); done(); return r.withdrawn.length ? `Withdrawn. ${r.withdrawn.length} imported products were taken away.` : "Withdrawn."; } const scope = field(form, "scope") === "products" ? "products" : "shop"; const list = productIDs(field(form, "list")); if (!list) throw new ApiError(400, "invalid", "Products are IMVU product IDs or shop links."); const r = unwrap( await api.imports.grants({ id }).patch({ ...(scope === "products" ? { products: list } : { exclude: list }), listed: form.get("listed") === "on", }), ); done(); return r.withdrawn.length ? `Saved. ${r.withdrawn.length} imported products it no longer covers were taken away.` : "Saved."; }); }