mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
[backend] Cleaner workaround for GoToSocial federation with authorized fetch
This commit is contained in:
parent
496454cf1f
commit
c7dc059116
2 changed files with 15 additions and 20 deletions
|
@ -19,9 +19,6 @@ import type { IObject } from "./type.js";
|
||||||
import { getApId } from "./type.js";
|
import { getApId } from "./type.js";
|
||||||
import { resolvePerson, updatePerson } from "./models/person.js";
|
import { resolvePerson, updatePerson } from "./models/person.js";
|
||||||
import {redisClient, subscriber} from "@/db/redis.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 publicKeyCache = new Cache<UserPublickey | null>("publicKey", 60 * 30);
|
||||||
const publicKeyByUserIdCache = new Cache<UserPublickey | null>(
|
const publicKeyByUserIdCache = new Cache<UserPublickey | null>(
|
||||||
|
@ -191,21 +188,7 @@ export default class DbResolver {
|
||||||
user: CacheableRemoteUser;
|
user: CacheableRemoteUser;
|
||||||
key: UserPublickey | null;
|
key: UserPublickey | null;
|
||||||
} | null> {
|
} | null> {
|
||||||
let user: CacheableRemoteUser;
|
const user = (await resolvePerson(uri)) as 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
|
|
||||||
|
|
|
@ -183,9 +183,21 @@ export async function createPerson(
|
||||||
|
|
||||||
if (resolver == null) resolver = new Resolver();
|
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}`);
|
logger.info(`Creating the Person: ${person.id}`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue