feat: IMVU imports on the hub: grants, requests and the importer's job queue
Creators grant a catalog leave to import their IMVU products (whole shop less exclusions, or listed products) from a linked IMVU account, agreeing to a versioned consent text; the catalog's team accepts or declines. Requests queue covered products (or add them to the library when imported already), suggest, or count. Importers claim jobs with the catalog's importer key, get t5de-import tokens, and the catalog registers imported revisions as published products owned by the creator. Narrowing or withdrawing a grant withdraws products; unlinking suspends grants; an hourly batch rechecks imported products with IMVU daily. Website: /imports and the console's catalog imports page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
eca1884918
commit
7d708aebdb
24 files changed
+6521
-153
No files matched your search
@@ -0,0 +1,305 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ActionForm, SubmitButton } from "@/components/forms";
|
||||
import { PageHeader, Tag } from "@/components/status";
|
||||
import { DateTime } from "@/components/time";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { api, unwrap, type ImportGrant } from "@/lib/api";
|
||||
import { ConsoleNav, requireConsole } from "../../../console-nav";
|
||||
import { decideGrant, retryJob, setImporter } from "../../actions";
|
||||
|
||||
export const metadata: Metadata = { title: "Imports" };
|
||||
|
||||
const statuses = ["queued", "claimed", "failed", "done"] as const;
|
||||
const grantTone = {
|
||||
pending: "strong",
|
||||
active: "online",
|
||||
declined: "neutral",
|
||||
suspended: "danger",
|
||||
withdrawn: "neutral",
|
||||
} as const;
|
||||
const jobTone = {
|
||||
queued: "neutral",
|
||||
claimed: "strong",
|
||||
failed: "danger",
|
||||
done: "online",
|
||||
} as const;
|
||||
const imvuPage = (id: number) => `https://www.imvu.com/shop/product.php?products_id=${id}`;
|
||||
|
||||
export default async function CatalogImports({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
searchParams: Promise<{ status?: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
await requireConsole(`/console/catalogs/${id}/imports`);
|
||||
const wanted = (await searchParams).status;
|
||||
const status = statuses.find((s) => s === wanted);
|
||||
const [catalogAnswer, answer] = await Promise.all([
|
||||
api.catalogs({ id }).get(),
|
||||
api.catalogs({ id }).importer.get({ query: status ? { status } : {} }),
|
||||
]);
|
||||
if (catalogAnswer.error || answer.error) notFound();
|
||||
const c = unwrap(catalogAnswer).catalog;
|
||||
const data = unwrap(answer);
|
||||
const can = data.permissions;
|
||||
const pending = data.grants.filter((g) => g.status === "pending");
|
||||
const others = data.grants.filter((g) => g.status !== "pending");
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={`${c.name}: Imports`}>
|
||||
<Link href={`/console/catalogs/${id}`} className="underline-offset-4 hover:underline">
|
||||
Back to the catalog
|
||||
</Link>
|
||||
</PageHeader>
|
||||
<ConsoleNav />
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
Importer{" "}
|
||||
<Tag tone={data.importer === "on" ? "online" : data.importer === "paused" ? "strong" : "neutral"}>
|
||||
{data.importer}
|
||||
</Tag>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{data.importer === "off"
|
||||
? "With imports on, creators can bring their IMVU products here, and your importer (t5de-importer, run beside the catalog) imports what they allow."
|
||||
: `The importer signs in with the catalog's ID (${id}) and its importer key. ${data.counts.queued} queued, ${data.counts.claimed} working, ${data.counts.failed} failed, ${data.counts.done} done.`}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
{(can.run || can.pause) && (
|
||||
<CardContent>
|
||||
<ActionForm action={setImporter} fields={{ id }}>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{data.importer === "off" ? (
|
||||
can.run && (
|
||||
<SubmitButton name="intent" value="on" pendingLabel="Turning on…">
|
||||
Turn imports on
|
||||
</SubmitButton>
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
{can.pause &&
|
||||
(data.importer === "paused" ? (
|
||||
<SubmitButton name="intent" value="resume" pendingLabel="Resuming…">
|
||||
Resume
|
||||
</SubmitButton>
|
||||
) : (
|
||||
<SubmitButton name="intent" value="pause" variant="outline" pendingLabel="Pausing…">
|
||||
Pause
|
||||
</SubmitButton>
|
||||
))}
|
||||
{can.run && (
|
||||
<SubmitButton
|
||||
name="intent"
|
||||
value="key"
|
||||
variant="outline"
|
||||
pendingLabel="Making one…"
|
||||
confirm="The old importer key stops working at once. Go on?"
|
||||
>
|
||||
New key
|
||||
</SubmitButton>
|
||||
)}
|
||||
{can.run && (
|
||||
<SubmitButton
|
||||
name="intent"
|
||||
value="off"
|
||||
variant="outline"
|
||||
pendingLabel="Turning off…"
|
||||
confirm="Turn imports off? No new grants, and the importer stops. What's imported stays."
|
||||
>
|
||||
Turn off
|
||||
</SubmitButton>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</ActionForm>
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{pending.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Waiting for You</CardTitle>
|
||||
<CardDescription>
|
||||
Creators asking this catalog to host their IMVU products. Nothing is imported until you accept.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y">
|
||||
{pending.map((g) => (
|
||||
<GrantRow key={g.id} id={id} grant={g} accept={can.accept} withdraw={can.withdraw} />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{others.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Grants</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y">
|
||||
{others.map((g) => (
|
||||
<GrantRow key={g.id} id={id} grant={g} accept={can.accept} withdraw={can.withdraw} />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Queue</CardTitle>
|
||||
<CardDescription className="flex flex-wrap gap-3">
|
||||
{[undefined, ...statuses].map((s) => (
|
||||
<Link
|
||||
key={s ?? "all"}
|
||||
href={`/console/catalogs/${id}/imports${s ? `?status=${s}` : ""}`}
|
||||
className={s === status ? "font-medium text-foreground" : "underline-offset-4 hover:underline"}
|
||||
>
|
||||
{s ?? "all"}
|
||||
</Link>
|
||||
))}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{data.jobs.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">Nothing here.</p>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>IMVU product</TableHead>
|
||||
<TableHead>Job</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Updated</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.jobs.map((j) => (
|
||||
<TableRow key={j.id}>
|
||||
<TableCell>
|
||||
<a
|
||||
href={imvuPage(j.imvuProduct)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="underline-offset-4 hover:underline"
|
||||
>
|
||||
{j.name || j.imvuProduct}
|
||||
</a>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{j.kind}
|
||||
{j.imvuRevision ? ` · revision ${j.imvuRevision}` : ""}
|
||||
</TableCell>
|
||||
<TableCell className="whitespace-normal">
|
||||
<Tag tone={jobTone[j.status]}>{j.status}</Tag>
|
||||
{j.reason && j.reason !== "unchanged" && (
|
||||
<span className="ml-2 text-xs text-muted-foreground">
|
||||
{j.reason}
|
||||
{j.attempts > 0 && ` (attempt ${j.attempts})`}
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
<DateTime iso={j.updatedAt} />
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
{can.run && (j.status === "failed" || j.status === "done") && (
|
||||
<ActionForm action={retryJob} fields={{ id, job: j.id }}>
|
||||
<SubmitButton size="sm" variant="outline" pendingLabel="Queuing…">
|
||||
{j.status === "failed" ? "Retry" : "Again"}
|
||||
</SubmitButton>
|
||||
</ActionForm>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function GrantRow({
|
||||
id,
|
||||
grant: g,
|
||||
accept,
|
||||
withdraw,
|
||||
}: {
|
||||
id: string;
|
||||
grant: ImportGrant;
|
||||
accept: boolean;
|
||||
withdraw: boolean;
|
||||
}) {
|
||||
const open = g.status === "pending" || g.status === "active" || g.status === "suspended";
|
||||
return (
|
||||
<div className="space-y-2 py-4 first:pt-0 last:pb-0">
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="font-medium">{g.imvuName || `IMVU account ${g.imvuId}`}</span>
|
||||
<span className="text-muted-foreground">(IMVU {g.imvuId})</span>
|
||||
<Tag tone={grantTone[g.status]}>{g.status}</Tag>
|
||||
{g.consentKind === "recorded" && <Tag>consent recorded by an admin</Tag>}
|
||||
<span className="text-xs text-muted-foreground">
|
||||
<DateTime iso={g.createdAt} dateOnly />
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm">
|
||||
{g.scope === "shop"
|
||||
? `The whole shop${g.exclude.length ? `, less ${g.exclude.length} left out` : ""}.`
|
||||
: `${g.products.length} chosen product${g.products.length === 1 ? "" : "s"}: ${g.products.slice(0, 10).join(", ")}${g.products.length > 10 ? "…" : ""}.`}{" "}
|
||||
{g.listed ? "Listed." : "Unlisted."}
|
||||
</p>
|
||||
{g.statusReason && <p className="text-sm text-muted-foreground">{g.statusReason}</p>}
|
||||
{open && (accept || withdraw) && (
|
||||
<ActionForm action={decideGrant} fields={{ id, grant: g.id }}>
|
||||
<div className="flex max-w-2xl flex-wrap gap-2">
|
||||
{(g.status === "pending" || withdraw) && (
|
||||
<Input
|
||||
name="reason"
|
||||
maxLength={500}
|
||||
placeholder={g.status === "pending" ? "Reason (if declining)" : "Reason (if ending)"}
|
||||
aria-label="Reason"
|
||||
className="min-w-56 flex-1"
|
||||
/>
|
||||
)}
|
||||
{g.status === "pending" && accept && (
|
||||
<>
|
||||
<SubmitButton name="intent" value="accept" pendingLabel="Accepting…">
|
||||
Accept
|
||||
</SubmitButton>
|
||||
<SubmitButton name="intent" value="decline" variant="outline" pendingLabel="Declining…">
|
||||
Decline
|
||||
</SubmitButton>
|
||||
</>
|
||||
)}
|
||||
{g.status !== "pending" && withdraw && (
|
||||
<SubmitButton
|
||||
name="intent"
|
||||
value="end"
|
||||
variant="outline"
|
||||
pendingLabel="Ending…"
|
||||
confirm="End this grant? Its imported products are taken away from everyone who has them."
|
||||
>
|
||||
End
|
||||
</SubmitButton>
|
||||
)}
|
||||
</div>
|
||||
</ActionForm>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -162,6 +162,24 @@ export default async function ManageCatalog({ params }: { params: Promise<{ id:
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{(has("import:accept") || has("import:pause")) && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
Imports <Tag tone={c.importer === "on" ? "online" : "neutral"}>{c.importer}</Tag>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Creators' IMVU products, imported with their permission: grants, the importer and its queue.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Link href={`/console/catalogs/${id}/imports`} className="text-sm underline underline-offset-4">
|
||||
Manage imports
|
||||
</Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{has("catalog:rotate-key") && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
|
||||
@@ -120,3 +120,56 @@ export async function membership(_: ActionState, form: FormData): Promise<Action
|
||||
return membership === "member" ? "You're a member." : "Asked. The catalog's team will decide.";
|
||||
});
|
||||
}
|
||||
|
||||
// ---- imports (docs/imports.md) ----
|
||||
|
||||
/** Turns the importer on (its key, shown once) or off, pauses or resumes it, or makes a new key. */
|
||||
export async function setImporter(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
return onCatalog(form, async (id) => {
|
||||
revalidatePath(`/console/catalogs/${id}/imports`);
|
||||
const intent = field(form, "intent");
|
||||
if (intent === "key") {
|
||||
const { key } = unwrap(await api.catalogs({ id }).importer.key.post());
|
||||
return `New importer key (shown once; put it in the importer's IMPORTER_KEY and restart it): ${key}`;
|
||||
}
|
||||
const body =
|
||||
intent === "on" ? { enabled: true } : intent === "off" ? { enabled: false } : { paused: intent === "pause" };
|
||||
const r = unwrap(await api.catalogs({ id }).importer.post(body));
|
||||
if (r.key) return `Imports are on. The importer's key (shown once; put it in IMPORTER_KEY): ${r.key}`;
|
||||
});
|
||||
}
|
||||
|
||||
/** The catalog's team accepts, declines or ends a creator's grant. */
|
||||
export async function decideGrant(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
return onCatalog(form, async (id) => {
|
||||
revalidatePath(`/console/catalogs/${id}/imports`);
|
||||
const grant = field(form, "grant");
|
||||
const intent = field(form, "intent");
|
||||
const reason = field(form, "reason");
|
||||
if (intent === "end") {
|
||||
unwrap(await api.imports.grants({ id: grant }).delete(reason ? { reason } : {}));
|
||||
return "Ended. Its imported products were taken away.";
|
||||
}
|
||||
const decision = intent === "accept" ? "accept" : "decline";
|
||||
const r = unwrap(
|
||||
await api.imports
|
||||
.grants({ id: grant })({ decision })
|
||||
.post(reason ? { reason } : {}),
|
||||
);
|
||||
return decision === "accept" ? `Accepted. ${r.queued} queued for the importer.` : "Declined.";
|
||||
});
|
||||
}
|
||||
|
||||
/** Retries a failed import job (or imports a product again). */
|
||||
export async function retryJob(_: ActionState, form: FormData): Promise<ActionState> {
|
||||
return onCatalog(form, async (id) => {
|
||||
revalidatePath(`/console/catalogs/${id}/imports`);
|
||||
unwrap(
|
||||
await api
|
||||
.catalogs({ id })
|
||||
.importer.jobs({ job: field(form, "job") })
|
||||
.retry.post(),
|
||||
);
|
||||
return "Queued.";
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,7 @@ import { notFound, redirect } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import { NavLink } from "@/components/header-client";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import {
|
||||
api,
|
||||
getMe,
|
||||
isModerator,
|
||||
unwrap,
|
||||
type ConsoleData,
|
||||
type Person,
|
||||
} from "@/lib/api";
|
||||
import { api, getMe, isModerator, unwrap, type ConsoleData, type Person } from "@/lib/api";
|
||||
|
||||
/** The signed-in moderator, or off to sign in; others get not found (these pages aren't for them). */
|
||||
export async function requireModerator(path: string): Promise<Person> {
|
||||
@@ -31,9 +24,7 @@ const loadConsole = cache(async (): Promise<ConsoleData | undefined> => {
|
||||
* The signed-in person and their console, or off to sign in. People who manage nothing get not found: the console
|
||||
* is for those controlling a product, catalog or room.
|
||||
*/
|
||||
export async function requireConsole(
|
||||
path: string,
|
||||
): Promise<{ me: Person; console: ConsoleData }> {
|
||||
export async function requireConsole(path: string): Promise<{ me: Person; console: ConsoleData }> {
|
||||
const me = await getMe();
|
||||
if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`);
|
||||
const data = await loadConsole();
|
||||
@@ -67,10 +58,7 @@ export async function ConsoleNav() {
|
||||
<AlertDescription>
|
||||
<span>
|
||||
Some of what you can do here needs it ({needed.join(", ")}).{" "}
|
||||
<Link
|
||||
href="/account"
|
||||
className="text-foreground underline underline-offset-4"
|
||||
>
|
||||
<Link href="/account" className="text-foreground underline underline-offset-4">
|
||||
Turn it on in your account
|
||||
</Link>
|
||||
.
|
||||
@@ -82,11 +70,7 @@ export async function ConsoleNav() {
|
||||
{tabs
|
||||
.filter((t) => sections.has(t.section))
|
||||
.map((t) => (
|
||||
<NavLink
|
||||
key={t.section}
|
||||
href={t.href}
|
||||
exact={t.section === "overview"}
|
||||
>
|
||||
<NavLink key={t.section} href={t.href} exact={t.section === "overview"}>
|
||||
{t.label}
|
||||
</NavLink>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user