fix(federation): 🐛 Fix fetching of ActivityPub users not working anymore

This commit is contained in:
Jesse Wierzbinski 2024-07-17 15:37:36 +02:00
parent 0e054e7cba
commit 42ff591e48
No known key found for this signature in database
12 changed files with 2182 additions and 8 deletions

View file

@ -139,7 +139,12 @@ export class Instance extends BaseInterface<typeof Instances> {
proxy: config.http.proxy.address,
});
if (!response.ok) {
if (
!(
response.ok &&
response.headers.get("content-type")?.includes("json")
)
) {
// If the server doesn't have a Lysand well-known endpoint, it's not a Lysand instance
// Try to resolve ActivityPub metadata instead
const data = await Instance.fetchActivityPubMetadata(url);

View file

@ -7,6 +7,7 @@ import type {
Mention as ApiMention,
} from "@lysand-org/client/types";
import { EntityValidator } from "@lysand-org/federation";
import type { FederationRequester } from "@lysand-org/federation/requester";
import type { Entity, User as LysandUser } from "@lysand-org/federation/types";
import {
type InferInsertModel,
@ -198,6 +199,20 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
);
}
static async webFinger(
manager: FederationRequester,
username: string,
): Promise<string> {
return (
(await manager.webFinger(username).catch(() => null)) ??
(await manager.webFinger(
username,
manager.url.hostname,
"application/activity+json",
))
);
}
static async getCount() {
return (
await db