Files
wanderer/web/src/lib/util/activitypub_util.ts
2025-06-24 17:55:59 +02:00

26 lines
641 B
TypeScript

export function splitUsername(handle: string, localDomain?: string) {
const cleaned = handle.replace(/^@/, "").trim();
if (!cleaned.includes("@")) {
return [cleaned, localDomain];
}
let [user, domain] = cleaned.split("@");
return [user, domain]
}
export function handleFromRecordWithIRI(record: any) {
if (!record.expand?.author) {
throw new Error("object has no author info")
}
if (!record.iri) {
return `@${record.expand.author.preferred_username}`
}
const url = new URL(record.iri ?? "")
return `@${record.expand.author.preferred_username}@${url.hostname}`
}