mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-21 19:53:50 +01:00
Fix updating remote user host for remote AP implementations that don't support webfinger uri queries
This commit is contained in:
parent
558b58a0cd
commit
06be4e108b
@ -48,7 +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"
|
||||
import { getSubjectHostFromUri, getSubjectHostFromRemoteUser } from "@/remote/resolve-user.js"
|
||||
|
||||
const logger = apLogger;
|
||||
|
||||
@ -425,11 +425,13 @@ export async function createPerson(
|
||||
* @param uri URI of Person
|
||||
* @param resolver Resolver
|
||||
* @param hint Hint of Person object (If this value is a valid Person, it is used for updating without Remote resolve)
|
||||
* @param userHint Hint of IRemoteUser object, used for updating user information for remotes that only support webfinger with acct: query
|
||||
*/
|
||||
export async function updatePerson(
|
||||
uri: string,
|
||||
resolver?: Resolver | null,
|
||||
hint?: IObject,
|
||||
userHint?: IRemoteUser,
|
||||
): Promise<void> {
|
||||
if (typeof uri !== "string") throw new Error("uri is not string");
|
||||
|
||||
@ -452,10 +454,10 @@ export async function updatePerson(
|
||||
|
||||
const person = validateActor(object, uri);
|
||||
|
||||
const host = await getSubjectHostFromUri(uri);
|
||||
|
||||
logger.info(`Updating the Person: ${person.id}`);
|
||||
|
||||
const host = await getSubjectHostFromUri(uri) ?? await getSubjectHostFromRemoteUser(userHint);
|
||||
|
||||
// Fetch avatar and header image
|
||||
const [avatar, banner] = await Promise.all(
|
||||
[person.icon, person.image].map((img) =>
|
||||
|
@ -187,6 +187,26 @@ export async function getSubjectHostFromUri(uri: string): Promise<string | null>
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSubjectHostFromAcct(acct: string): Promise<string | null> {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function getSubjectHostFromRemoteUser(user: IRemoteUser | undefined): Promise<string | null> {
|
||||
return user ? getSubjectHostFromAcct(`${user.username}@${user.host}`) : null;
|
||||
}
|
||||
|
||||
async function resolveUserWebFinger(acctLower: string, recurse: boolean = true): Promise<{
|
||||
subject: string,
|
||||
self: {
|
||||
|
@ -18,5 +18,5 @@ export const paramDef = {
|
||||
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const user = await getRemoteUser(ps.userId);
|
||||
await updatePerson(user.uri!);
|
||||
await updatePerson(user.uri!, undefined, undefined, user);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user