Resolve actual subject host on createPerson

This commit is contained in:
Laura Hausmann 2023-09-05 23:10:27 +02:00
parent 35f7bde1a4
commit 59571f2372
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 18 additions and 1 deletions

View File

@ -48,6 +48,7 @@ import Resolver from "../resolver.js";
import { extractApHashtags } from "./tag.js";
import { resolveNote, extractEmojis } from "./note.js";
import { resolveImage } from "./image.js";
import { getSubjectHostFromUri } from "@/remote/resolve-user.js"
const logger = apLogger;
@ -184,7 +185,7 @@ export async function createPerson(
logger.info(`Creating the Person: ${person.id}`);
const host = subjectHost ?? toPuny(new URL(object.id).hostname);
const host = subjectHost ?? await getSubjectHostFromUri(object.id) ?? toPuny(new URL(object.id).hostname);
const { fields } = analyzeAttachments(person.attachment || []);

View File

@ -171,6 +171,22 @@ export async function resolveUser(
return user;
}
export async function getSubjectHostFromUri( uri: string): Promise<string | null> {
try {
const acct = subjectToAcct((await webFinger(uri)).subject);
const res = await resolveUserWebFinger(acct.toLowerCase());
const finalAcct = subjectToAcct(res.subject);
const m = finalAcct.match(/^([^@]+)@(.*)/);
if (!m) {
return null;
}
return m[2];
}
catch {
return null;
}
}
async function resolveUserWebFinger(acctLower: string, recurse: boolean = true): Promise<{
subject: string,
self: {