mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[backend] Cleaner workaround for GoToSocial federation with authorized fetch
This commit is contained in:
parent
496454cf1f
commit
c7dc059116
@ -19,9 +19,6 @@ import type { IObject } from "./type.js";
|
||||
import { getApId } from "./type.js";
|
||||
import { resolvePerson, updatePerson } from "./models/person.js";
|
||||
import {redisClient, subscriber} from "@/db/redis.js";
|
||||
import { remoteLogger } from "@/remote/logger.js";
|
||||
|
||||
const logger = remoteLogger.createSubLogger("db-resolver");
|
||||
|
||||
const publicKeyCache = new Cache<UserPublickey | null>("publicKey", 60 * 30);
|
||||
const publicKeyByUserIdCache = new Cache<UserPublickey | null>(
|
||||
@ -191,21 +188,7 @@ export default class DbResolver {
|
||||
user: CacheableRemoteUser;
|
||||
key: UserPublickey | null;
|
||||
} | null> {
|
||||
let user: CacheableRemoteUser;
|
||||
|
||||
try {
|
||||
user = (await resolvePerson(uri)) as CacheableRemoteUser;
|
||||
}
|
||||
catch (e: any) {
|
||||
// Bypass GoToSocial issue #1186 (ref: https://github.com/superseriousbusiness/gotosocial/issues/1186)
|
||||
if (e.message === 'invalid Actor: wrong inbox' && uri.match(/https?:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9_]+\/main-key$/)) {
|
||||
logger.warn(`Failed to resolve ${uri}, re-attempting without trailing /main-key`);
|
||||
user = (await resolvePerson(uri.substring(0, uri.length - 9))) as CacheableRemoteUser;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
const user = (await resolvePerson(uri)) as CacheableRemoteUser;
|
||||
|
||||
if (user == null) return null;
|
||||
|
||||
|
@ -183,9 +183,21 @@ export async function createPerson(
|
||||
|
||||
if (resolver == null) resolver = new Resolver();
|
||||
|
||||
const object = (await resolver.resolve(uri)) as any;
|
||||
let object = (await resolver.resolve(uri)) as any;
|
||||
|
||||
const person = validateActor(object, uri);
|
||||
let person: IActor;
|
||||
try {
|
||||
person = validateActor(object, uri);
|
||||
}
|
||||
catch (e: any) {
|
||||
if (typeof object.publicKey?.owner !== 'string')
|
||||
throw e;
|
||||
|
||||
// Work around GoToSocial issue #1186 (ref: https://github.com/superseriousbusiness/gotosocial/issues/1186)
|
||||
logger.info(`Received stub actor, re-resolving with key owner uri: ${object.publicKey.owner}`);
|
||||
object = (await resolver.resolve(object.publicKey.owner)) as any;
|
||||
person = validateActor(object, uri);
|
||||
}
|
||||
|
||||
logger.info(`Creating the Person: ${person.id}`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user