Fix initial fetch of actual remote user host for remote gotosocial instances on createPerson, resolves #204

This commit is contained in:
Laura Hausmann 2023-09-11 18:37:18 +02:00
parent 43f136c50f
commit 86defdffd3
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 13 additions and 3 deletions

View File

@ -48,7 +48,11 @@ import Resolver from "../resolver.js";
import { extractApHashtags } from "./tag.js"; import { extractApHashtags } from "./tag.js";
import { resolveNote, extractEmojis } from "./note.js"; import { resolveNote, extractEmojis } from "./note.js";
import { resolveImage } from "./image.js"; import { resolveImage } from "./image.js";
import { getSubjectHostFromUri, getSubjectHostFromRemoteUser } from "@/remote/resolve-user.js" import {
getSubjectHostFromUri,
getSubjectHostFromRemoteUser,
getSubjectHostFromAcctParts
} from "@/remote/resolve-user.js"
const logger = apLogger; const logger = apLogger;
@ -185,10 +189,12 @@ export async function createPerson(
logger.info(`Creating the Person: ${person.id}`); logger.info(`Creating the Person: ${person.id}`);
const host = subjectHost ?? await getSubjectHostFromUri(object.id) ?? toPuny(new URL(object.id).hostname);
const usernameLower = person.preferredUsername?.toLowerCase(); const usernameLower = person.preferredUsername?.toLowerCase();
const urlHostname = toPuny(new URL(object.id).hostname);
const host = subjectHost ?? await getSubjectHostFromUri(object.id) ?? await getSubjectHostFromAcctParts(usernameLower, urlHostname) ?? urlHostname;
if (usernameLower !== null) { if (usernameLower !== null) {
let checkUser = (await Users.findOneBy({ let checkUser = (await Users.findOneBy({
usernameLower: usernameLower, usernameLower: usernameLower,

View File

@ -207,6 +207,10 @@ export async function getSubjectHostFromRemoteUser(user: IRemoteUser | undefined
return user ? getSubjectHostFromAcct(`${user.username}@${user.host}`) : null; return user ? getSubjectHostFromAcct(`${user.username}@${user.host}`) : null;
} }
export async function getSubjectHostFromAcctParts(username?: string | undefined, host?: string | undefined): Promise<string | null> {
return username !== null && host !== null ? getSubjectHostFromAcct(`${username}@${host}`) : null;
}
async function resolveUserWebFinger(acctLower: string, recurse: boolean = true): Promise<{ async function resolveUserWebFinger(acctLower: string, recurse: boolean = true): Promise<{
subject: string, subject: string,
self: { self: {