kopia lustrzana https://github.com/cloudflare/wildebeest
delivery user-agent and accept header
refs https://github.com/cloudflare/wildebeest/issues/80pull/203/head
rodzic
aac4d74c8b
commit
67f76d2a19
|
@ -7,12 +7,14 @@ import type { Actor } from './actors'
|
||||||
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
|
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
|
||||||
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
|
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
|
||||||
import { getFollowers } from 'wildebeest/backend/src/mastodon/follow'
|
import { getFollowers } from 'wildebeest/backend/src/mastodon/follow'
|
||||||
|
import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions'
|
||||||
const headers = {
|
|
||||||
'content-type': 'application/activity+json',
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
|
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)
|
const body = JSON.stringify(activity)
|
||||||
console.log({ body })
|
console.log({ body })
|
||||||
const req = new Request(to.inbox, {
|
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()
|
const body = await res.text()
|
||||||
throw new Error(`delivery to ${to.inbox} returned ${res.status}: ${body}`)
|
throw new Error(`delivery to ${to.inbox} returned ${res.status}: ${body}`)
|
||||||
}
|
}
|
||||||
{
|
console.log(`${to.inbox} returned 200`)
|
||||||
const body = await res.text()
|
|
||||||
console.log(`${to.inbox} returned 200: ${body}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deliverFollowers(
|
export async function deliverFollowers(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as packagejson from '../package.json'
|
import * as packagejson from '../package.json'
|
||||||
|
|
||||||
// https://github.com/mastodon/mastodon/blob/main/CHANGELOG.md
|
// 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
|
export const WILDEBEEST_VERSION = packagejson.version
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
|
||||||
import type { Env } from './'
|
import type { Env } from './'
|
||||||
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
|
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
|
||||||
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
|
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
|
||||||
|
import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver'
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'content-type': 'application/activity+json',
|
'content-type': 'application/activity+json',
|
||||||
|
@ -18,26 +19,6 @@ export async function handleDeliverMessage(env: Env, actor: Actor, message: Deli
|
||||||
return
|
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)
|
const signingKey = await getSigningKey(message.userKEK, env.DATABASE, actor)
|
||||||
await signRequest(req, signingKey, actor.id)
|
await deliverToActor(signingKey, actor, targetActor, message.activity)
|
||||||
|
|
||||||
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}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ describe('Consumer', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.url.toString() === 'https://example.com/inbox') {
|
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')
|
assert.equal(input.method, 'POST')
|
||||||
receivedActivity = await input.json()
|
receivedActivity = await input.json()
|
||||||
return new Response('')
|
return new Response('')
|
||||||
|
|
Ładowanie…
Reference in New Issue