diff options
Diffstat (limited to 'src/activitypub')
-rw-r--r-- | src/activitypub/federation/queue.ts | 9 | ||||
-rw-r--r-- | src/activitypub/federation/utils.ts | 17 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/activitypub/federation/queue.ts b/src/activitypub/federation/queue.ts index c62017e6..0f08dd85 100644 --- a/src/activitypub/federation/queue.ts +++ b/src/activitypub/federation/queue.ts @@ -42,13 +42,8 @@ class FederationQueue { ]) { if (!recv) continue; - if (typeof recv != "string") { - console.warn( - `TODO: activity with non-string destination was not sent`, - recv, - ); - continue; - } + // this is wrong? + if (typeof recv != "string") continue; if (recv == "https://www.w3.org/ns/activitystreams#Public") { console.debug(`TODO: Skipping sending activity to #Public`); diff --git a/src/activitypub/federation/utils.ts b/src/activitypub/federation/utils.ts index 7f1d5e6a..520c292e 100644 --- a/src/activitypub/federation/utils.ts +++ b/src/activitypub/federation/utils.ts @@ -2,7 +2,9 @@ import { DEFAULT_FETCH_OPTIONS } from "@spacebar/api"; import { ActorType, Config, + Debug, FederationActivity, + FederationCache, FederationKey, OrmUtils, Snowflake, @@ -26,6 +28,10 @@ import TurndownService from "turndown"; import { federationQueue } from "./queue"; export const ACTIVITYSTREAMS_CONTEXT = "https://www.w3.org/ns/activitystreams"; +export const LOG_NAMES = { + webfinger: "Webfinger", + remote: "Remote", +}; export const fetchOpts = Object.freeze( OrmUtils.mergeDeep(DEFAULT_FETCH_OPTIONS, { @@ -52,6 +58,11 @@ export const resolveAPObject = async <T extends AnyAPObject>( // we were already given an object if (typeof data != "string") return data; + const cache = await FederationCache.findOne({ where: { id: data } }); + if (cache) return cache.toJSON() as T; + + Debug(LOG_NAMES.remote, `Fetching from remote ${data}`); + const agent = new ProxyAgent(); const ret = await fetch(data, { ...fetchOpts, @@ -62,6 +73,10 @@ export const resolveAPObject = async <T extends AnyAPObject>( if (!hasAPContext(json)) throw new APError("Object is not APObject"); + setImmediate(async () => { + await FederationCache.create({ id: json.id, data: json }).save(); + }); + return json as T; }; @@ -95,6 +110,8 @@ export const resolveWebfinger = async ( ): Promise<AnyAPObject> => { const { domain } = splitQualifiedMention(lookup); + Debug(LOG_NAMES.webfinger, `Performing lookup ${lookup}`); + const agent = new ProxyAgent(); const wellknown = (await fetch( `https://${domain}/.well-known/webfinger?resource=${lookup}`, |