feat: importer IMVU accounts and settings from the console
Pull request / title (pull_request) Successful in 2s
CI / test (pull_request) Successful in 1m18s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped

The importer sends its RSA public key (POST /importer/hello); the console
looks IMVU accounts up, confirms them in a dialog, and seals each password
in the browser for that key. The hub keeps only the sealed copy, until the
importer confirms it has it. Accounts are tried in order; settings (rate,
jobs at once) come from the console too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-11-07 10:01:11 -08:00
1 parent d716aabbd2
commit dcc39d82ab
16 files changed
+5505 -9

No files matched your search

+87 -1
View File
@@ -1,7 +1,7 @@
"use server";
// Managing a catalog from the console: settings, key, team, members, invitations, what it hosts, suspension.
import { revalidatePath } from "next/cache";
import { api, unwrap } from "@/lib/api";
import { api, ApiError, unwrap } from "@/lib/api";
import { attempt, field, type ActionState } from "@/lib/actions";
/** Runs a change to a catalog, then shows its pages again. */
@@ -173,3 +173,89 @@ export async function retryJob(_: ActionState, form: FormData): Promise<ActionSt
return "Queued.";
});
}
// ---- the importer program and its IMVU accounts (docs/imports.md "IMVU accounts") ----
export type ImvuAccountInfo = {
imvuId: number;
username: string;
picture: string | null;
accessPass: boolean;
ageVerified: boolean;
};
/** Called from the browser: an error to show, or what was asked for. */
async function answered<T>(fn: () => Promise<T>): Promise<{ error: string } | { ok: T }> {
try {
return { ok: await fn() };
} catch (e) {
if (e instanceof ApiError) return { error: e.message };
throw e;
}
}
/** Looks an IMVU account up for the confirmation dialog (public info only). */
export async function lookupImporterAccount(id: string, username: string) {
return answered<ImvuAccountInfo>(async () =>
unwrap(await api.catalogs({ id }).importer["imvu-account"].get({ query: { username: username.trim() } })),
);
}
/**
* Adds an account, or gives one a new password (account set). The password arrives sealed in the browser for the
* importer's key; it never passes through here readable.
*/
export async function saveImporterAccount(
id: string,
a: { imvuId: number; account?: string; sealed: string; fingerprint: string },
) {
const r = await answered(async () => {
if (a.account)
unwrap(
await api
.catalogs({ id })
.importer.accounts({ account: a.account })
.password.put({ sealed: a.sealed, fingerprint: a.fingerprint }),
);
else unwrap(await api.catalogs({ id }).importer.accounts.post({ imvuId: a.imvuId, sealed: a.sealed, fingerprint: a.fingerprint }));
return true;
});
revalidatePath(`/console/catalogs/${id}/imports`);
return r;
}
/** Moves an account up or down, or removes it. */
export async function changeImporterAccount(_: ActionState, form: FormData): Promise<ActionState> {
const id = field(form, "id");
const account = field(form, "account");
return attempt(async () => {
const intent = field(form, "intent");
if (intent === "remove") {
unwrap(await api.catalogs({ id }).importer.accounts({ account }).delete());
revalidatePath(`/console/catalogs/${id}/imports`);
return "Removed. The importer forgets it within a minute.";
}
unwrap(
await api
.catalogs({ id })
.importer.accounts({ account })
.move.post({ direction: intent === "up" ? "up" : "down" }),
);
revalidatePath(`/console/catalogs/${id}/imports`);
});
}
/** The importer's settings. */
export async function setImporterSettings(_: ActionState, form: FormData): Promise<ActionState> {
const id = field(form, "id");
return attempt(async () => {
unwrap(
await api.catalogs({ id }).importer.settings.post({
rate: Number(field(form, "rate")),
concurrency: Number(field(form, "concurrency")),
}),
);
revalidatePath(`/console/catalogs/${id}/imports`);
return "Saved. The importer picks it up within a minute.";
});
}