import { Famulor } from "famulor-sdk";
import { readFile } from "node:fs/promises";
const photo = new Blob([new Uint8Array(await readFile("photo.jpg"))], { type: "image/jpeg" });
const client = new Famulor({ apiKey: process.env.FAMULOR_API_KEY! });
const quote = await client.avatars.capability();
const upload = await client.avatars.prepareUpload({
name: "My avatar", style: "custom",
content_type: "image/jpeg", size_bytes: photo.size,
});
const form = new FormData();
form.append("", photo, "photo.jpg");
form.append("cacheControl", "0");
const uploaded = await fetch(upload.data.upload_url, {
method: "PUT", headers: { "x-upsert": "false" }, body: form,
});
if (!uploaded.ok) throw new Error("Photo upload failed");
const avatar = await client.avatars.submit({
id: upload.data.id, consent: true,
expected_credits: quote.data.creation_credits,
});
const status = await client.avatars.get(avatar.data.id);
const catalog = await client.avatars.catalog({ style: "custom" });