profile

tcmts.atproto.profile · #tvg5recs · function · runs on the server

uses tcmts.atproto.pdsOf, which uses tcmts.atproto.localNetwork, which uses process

Someone's Bluesky profile (app.bsky.actor.profile/self), as their repository signs it (#iqqihysc): their display name, bio and picture (where their PDS serves it). Nothing, if they have none.

import { didDocument, NoSuchRecord, pdsOf, verifiedRecord } from "#codebase/tcmts/atproto";

export async function profile(
  did: string,
): Promise<{ displayName?: string; description?: string; avatar?: string }> {
  let record: {
    displayName?: unknown;
    description?: unknown;
    avatar?: { ref?: { $link?: unknown } };
  };
  try {
    record = (await verifiedRecord(did, "app.bsky.actor.profile", "self")).record as typeof record;
  } catch (e) {
    if (e instanceof NoSuchRecord) return {};
    throw e;
  }
  const text = (v: unknown, max: number) =>
    typeof v === "string" && v.trim() ? v.trim().slice(0, max) : undefined;
  const displayName = text(record.displayName, 640);
  const description = text(record.description, 2560);
  const cid = record.avatar?.ref?.$link;
  const avatar =
    typeof cid === "string" && /^[a-z0-9]+$/.test(cid)
      ? `${pdsOf(await didDocument(did), did)}/xrpc/com.atproto.sync.getBlob?${new URLSearchParams({ did, cid })}`
      : undefined;
  return {
    ...(displayName ? { displayName } : {}),
    ...(description ? { description } : {}),
    ...(avatar ? { avatar } : {}),
  };
}

uses

used by