diff --git a/backend/src/activitypub/deliver.ts b/backend/src/activitypub/deliver.ts index c743839..34d0369 100644 --- a/backend/src/activitypub/deliver.ts +++ b/backend/src/activitypub/deliver.ts @@ -7,12 +7,14 @@ import type { Actor } from './actors' import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage' import { signRequest } from 'wildebeest/backend/src/utils/http-signing' import { getFollowers } from 'wildebeest/backend/src/mastodon/follow' - -const headers = { - 'content-type': 'application/activity+json', -} +import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions' export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) { + const headers = { + Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent': `Wildebeest/${WILDEBEEST_VERSION} Mastodon/${MASTODON_API_VERSION}`, + } + const body = JSON.stringify(activity) console.log({ body }) const req = new Request(to.inbox, { @@ -29,10 +31,7 @@ export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Act const body = await res.text() throw new Error(`delivery to ${to.inbox} returned ${res.status}: ${body}`) } - { - const body = await res.text() - console.log(`${to.inbox} returned 200: ${body}`) - } + console.log(`${to.inbox} returned 200`) } export async function deliverFollowers( diff --git a/config/versions.ts b/config/versions.ts index 5ecefae..737dd2e 100644 --- a/config/versions.ts +++ b/config/versions.ts @@ -1,7 +1,7 @@ import * as packagejson from '../package.json' // https://github.com/mastodon/mastodon/blob/main/CHANGELOG.md -const MASTODON_API_VERSION = '4.0.2' +export const MASTODON_API_VERSION = '4.0.2' export const WILDEBEEST_VERSION = packagejson.version diff --git a/consumer/src/deliver.ts b/consumer/src/deliver.ts index d3a08a5..d1a7a78 100644 --- a/consumer/src/deliver.ts +++ b/consumer/src/deliver.ts @@ -5,6 +5,7 @@ import type { Actor } from 'wildebeest/backend/src/activitypub/actors' import type { Env } from './' import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage' import { signRequest } from 'wildebeest/backend/src/utils/http-signing' +import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver' const headers = { 'content-type': 'application/activity+json', @@ -18,26 +19,6 @@ export async function handleDeliverMessage(env: Env, actor: Actor, message: Deli return } - const body = JSON.stringify(message.activity) - - const req = new Request(targetActor.inbox, { - method: 'POST', - body, - headers, - }) - const digest = await generateDigestHeader(body) - req.headers.set('Digest', digest) const signingKey = await getSigningKey(message.userKEK, env.DATABASE, actor) - await signRequest(req, signingKey, actor.id) - - const res = await fetch(req) - if (!res.ok) { - const body = await res.text() - console.error(`delivery to ${targetActor.inbox} returned ${res.status}: ${body}`) - return - } - { - const body = await res.text() - console.log(`${targetActor.inbox} returned 200: ${body}`) - } + await deliverToActor(signingKey, actor, targetActor, message.activity) } diff --git a/consumer/test/consumer.spec.ts b/consumer/test/consumer.spec.ts index 0f1106e..7ab8e2e 100644 --- a/consumer/test/consumer.spec.ts +++ b/consumer/test/consumer.spec.ts @@ -29,6 +29,8 @@ describe('Consumer', () => { } if (input.url.toString() === 'https://example.com/inbox') { + assert(input.headers.get('accept').includes('json')) + assert(input.headers.get('user-agent').includes('Wildebeest')) assert.equal(input.method, 'POST') receivedActivity = await input.json() return new Response('')