feat: IMVU imports on the hub: grants, requests and the importer's job queue (#13)
Phase 4a (docs/imports.md): the hub's side of IMVU imports. **Grants** - A creator picks one of their linked IMVU accounts and a catalog with imports on. They choose the whole shop (with exclusions) or listed products, listed or unlisted, and agree to a versioned consent text (`imports.ts` `consent`). - The catalog's team (`import:accept`) accepts or declines, and the creator is notified. Accepting queues what people already asked for, plus a grant's listed products. - The creator can change what's covered or withdraw it; the team (`import:withdraw`, which moderators also have) can end it. - Withdrawn products are removed the way moderation removes products: their hosting is dropped and their files go in the catalogs' changes feed. If another catalog's active grant still covers a product, it's only delisted from this catalog. - Unlinking an IMVU account, or someone else linking it, suspends its grants. **Requests** - Anyone signed in can ask for an IMVU product (an ID or a shop link). The answer is one of: - `added`: already imported, and now in their library - `queued`: delivered to their library once imported - `suggested`: the creator grants by listed products, and will see the request - `counted`: no grant covers it yet - Creators see request counts for their accounts, and moderators see the most-requested creators. - At most 50 requests a day per person. **Importer** - Importers sign in with `Authorization: Importer <catalog>:<key>`; turning imports on returns the key once. The catalog's importer can be paused (`import:pause`). - Importers claim jobs, get `t5de-import` tokens for a revision, and report outcomes. - Claims time out after 30 minutes. Failures retry after 1 min, 10 min, 1 h, then daily, and fail for good after 5 attempts. - `POST /catalog/revisions` takes `importToken` instead of `uploadToken`. The result is a published product owned by the creator (`product.imvu_product`, `product_revision.imvu_revision`). If another catalog already imported the same IMVU revision, this catalog hosts it too. - Every hour, the API rechecks a batch of imported products with IMVU (each at most once a day). A product gone from IMVU, or now another creator's, is withdrawn. One rated AP becomes adult. If it's still covered, a recheck job looks for new revisions. **Website** - `/imports`: ask for a product; bring your products; change or withdraw a grant; what people asked for. It's linked from the account page. - The console's catalog page has an Imports card leading to `/console/catalogs/:id/imports`: - importer on, off, pause and resume, and a new key - pending grants to accept or decline - grants to end - the queue, filtered by status, with retry - Notification text for the two new notification types. **Checks** - **Tests:** `test/imports.test.ts` covers the whole flow, from grant to withdrawal. All 58 API tests pass, and type checks pass. - **Scratch hub:** through the console forms, I turned imports on (the key was shown once), paused and resumed. I checked that importer claims accept the key and refuse a wrong one, that `/imports` renders, and that a request while IMVU is unreachable says "IMVU didn't answer." - **IMVU fields not checked live:** `api.imvu.com` times out from the dev machine. The product fields (`product_name`, `creator_cid`, `creator_name`, `rating`, `is_purchasable`) are what the design recorded; the spike will check them. **Formatting** - `two-factor-card.tsx`, `signin-form.tsx` and `console-nav.tsx` are only reformatted. I'd run Prettier on them at its default 80 columns in #12, but the repo is wrapped at about 120. **Still to do (4b and later)** - admin-recorded grants, proofs and unclaimed creators (and claiming them) - `GET /imports/available` for the proxy's shop button - t5de-catalog accepting `t5de-import` tokens on uploads - the spike, then `t5de-importer` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Phase 4a (docs/imports.md): the hub's side of IMVU imports. **Grants** - A creator picks one of their linked IMVU accounts and a catalog with imports on. They choose the whole shop (with exclusions) or listed products, listed or unlisted, and agree to a versioned consent text (`imports.ts` `consent`). - The catalog's team (`import:accept`) accepts or declines, and the creator is notified. Accepting queues what people already asked for, plus a grant's listed products. - The creator can change what's covered or withdraw it; the team (`import:withdraw`, which moderators also have) can end it. - Withdrawn products are removed the way moderation removes products: their hosting is dropped and their files go in the catalogs' changes feed. If another catalog's active grant still covers a product, it's only delisted from this catalog. - Unlinking an IMVU account, or someone else linking it, suspends its grants. **Requests** - Anyone signed in can ask for an IMVU product (an ID or a shop link). The answer is one of: - `added`: already imported, and now in their library - `queued`: delivered to their library once imported - `suggested`: the creator grants by listed products, and will see the request - `counted`: no grant covers it yet - Creators see request counts for their accounts, and moderators see the most-requested creators. - At most 50 requests a day per person. **Importer** - Importers sign in with `Authorization: Importer <catalog>:<key>`; turning imports on returns the key once. The catalog's importer can be paused (`import:pause`). - Importers claim jobs, get `t5de-import` tokens for a revision, and report outcomes. - Claims time out after 30 minutes. Failures retry after 1 min, 10 min, 1 h, then daily, and fail for good after 5 attempts. - `POST /catalog/revisions` takes `importToken` instead of `uploadToken`. The result is a published product owned by the creator (`product.imvu_product`, `product_revision.imvu_revision`). If another catalog already imported the same IMVU revision, this catalog hosts it too. - Every hour, the API rechecks a batch of imported products with IMVU (each at most once a day). A product gone from IMVU, or now another creator's, is withdrawn. One rated AP becomes adult. If it's still covered, a recheck job looks for new revisions. **Website** - `/imports`: ask for a product; bring your products; change or withdraw a grant; what people asked for. It's linked from the account page. - The console's catalog page has an Imports card leading to `/console/catalogs/:id/imports`: - importer on, off, pause and resume, and a new key - pending grants to accept or decline - grants to end - the queue, filtered by status, with retry - Notification text for the two new notification types. **Checks** - **Tests:** `test/imports.test.ts` covers the whole flow, from grant to withdrawal. All 58 API tests pass, and type checks pass. - **Scratch hub:** through the console forms, I turned imports on (the key was shown once), paused and resumed. I checked that importer claims accept the key and refuse a wrong one, that `/imports` renders, and that a request while IMVU is unreachable says "IMVU didn't answer." - **IMVU fields not checked live:** `api.imvu.com` times out from the dev machine. The product fields (`product_name`, `creator_cid`, `creator_name`, `rating`, `is_purchasable`) are what the design recorded; the spike will check them. **Formatting** - `two-factor-card.tsx`, `signin-form.tsx` and `console-nav.tsx` are only reformatted. I'd run Prettier on them at its default 80 columns in #12, but the repo is wrapped at about 120. **Still to do (4b and later)** - admin-recorded grants, proofs and unclaimed creators (and claiming them) - `GET /imports/available` for the proxy's shop button - t5de-catalog accepting `t5de-import` tokens on uploads - the spike, then `t5de-importer` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #13.
This commit is contained in:
1 parent
eca1884918
commit
7ece681eef
24 files changed
+6565
-158
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>
|
||||
|
||||
Reference in new issue
Block a user