kopia lustrzana https://github.com/cloudflare/wildebeest
Merge pull request #203 from cloudflare/sven/improve-delivery-request
delivery user-agent and accept headerpull/205/head
commit
712d1f9c40
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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('')
|
||||
|
|
Ładowanie…
Reference in New Issue