kopia lustrzana https://github.com/cloudflare/wildebeest
Merge pull request #215 from cloudflare/sven/improve-ua
clarify UA used for federationpull/222/head
commit
1d9775b3aa
|
@ -248,7 +248,7 @@ export async function handle(
|
||||||
await acceptFollowing(db, originalActor, receiver)
|
await acceptFollowing(db, originalActor, receiver)
|
||||||
const reply = accept.create(receiver, activity)
|
const reply = accept.create(receiver, activity)
|
||||||
const signingKey = await getSigningKey(userKEK, db, receiver)
|
const signingKey = await getSigningKey(userKEK, db, receiver)
|
||||||
await deliverToActor(signingKey, receiver, originalActor, reply)
|
await deliverToActor(signingKey, receiver, originalActor, reply, domain)
|
||||||
|
|
||||||
// Notify the user
|
// Notify the user
|
||||||
const notifId = await insertFollowNotification(db, receiver, originalActor)
|
const notifId = await insertFollowNotification(db, receiver, originalActor)
|
||||||
|
|
|
@ -7,14 +7,20 @@ 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'
|
import { getFederationUA } from 'wildebeest/config/ua'
|
||||||
|
|
||||||
const MAX_BATCH_SIZE = 100
|
const MAX_BATCH_SIZE = 100
|
||||||
|
|
||||||
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
|
export async function deliverToActor(
|
||||||
|
signingKey: CryptoKey,
|
||||||
|
from: Actor,
|
||||||
|
to: Actor,
|
||||||
|
activity: Activity,
|
||||||
|
domain: string
|
||||||
|
) {
|
||||||
const headers = {
|
const headers = {
|
||||||
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||||
'User-Agent': `Wildebeest/${WILDEBEEST_VERSION} Mastodon/${MASTODON_API_VERSION}`,
|
'User-Agent': getFederationUA(domain),
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = JSON.stringify(activity)
|
const body = JSON.stringify(activity)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions'
|
||||||
|
|
||||||
|
export function getFederationUA(domain: string): string {
|
||||||
|
return `Wildebeest/${WILDEBEEST_VERSION} (Mastodon/${MASTODON_API_VERSION}; +${domain})`
|
||||||
|
}
|
|
@ -20,5 +20,5 @@ export async function handleDeliverMessage(env: Env, actor: Actor, message: Deli
|
||||||
}
|
}
|
||||||
|
|
||||||
const signingKey = await getSigningKey(message.userKEK, env.DATABASE, actor)
|
const signingKey = await getSigningKey(message.userKEK, env.DATABASE, actor)
|
||||||
await deliverToActor(signingKey, actor, targetActor, message.activity)
|
await deliverToActor(signingKey, actor, targetActor, message.activity, env.DOMAIN)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ 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('accept').includes('json'))
|
||||||
assert(input.headers.get('user-agent').includes('Wildebeest'))
|
assert(input.headers.get('user-agent').includes('Wildebeest'))
|
||||||
|
assert(input.headers.get('user-agent').includes(domain))
|
||||||
assert.equal(input.method, 'POST')
|
assert.equal(input.method, 'POST')
|
||||||
receivedActivity = await input.json()
|
receivedActivity = await input.json()
|
||||||
return new Response('')
|
return new Response('')
|
||||||
|
@ -60,6 +61,7 @@ describe('Consumer', () => {
|
||||||
|
|
||||||
const env = {
|
const env = {
|
||||||
DATABASE: db,
|
DATABASE: db,
|
||||||
|
DOMAIN: domain,
|
||||||
} as any
|
} as any
|
||||||
await handleDeliverMessage(env, actor, message)
|
await handleDeliverMessage(env, actor, message)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ export async function handleRequest(
|
||||||
if (request.method !== 'POST') {
|
if (request.method !== 'POST') {
|
||||||
return new Response('', { status: 400 })
|
return new Response('', { status: 400 })
|
||||||
}
|
}
|
||||||
|
const domain = new URL(request.url).hostname
|
||||||
const handle = parseHandle(id)
|
const handle = parseHandle(id)
|
||||||
|
|
||||||
// Only allow to follow remote users
|
// Only allow to follow remote users
|
||||||
|
@ -44,7 +44,7 @@ export async function handleRequest(
|
||||||
|
|
||||||
const activity = follow.create(connectedActor, targetActor)
|
const activity = follow.create(connectedActor, targetActor)
|
||||||
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
||||||
await deliverToActor(signingKey, connectedActor, targetActor, activity)
|
await deliverToActor(signingKey, connectedActor, targetActor, activity, domain)
|
||||||
|
|
||||||
const res: Relationship = {
|
const res: Relationship = {
|
||||||
id: await addFollowing(db, connectedActor, targetActor, acct),
|
id: await addFollowing(db, connectedActor, targetActor, acct),
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function handleRequest(
|
||||||
if (request.method !== 'POST') {
|
if (request.method !== 'POST') {
|
||||||
return new Response('', { status: 400 })
|
return new Response('', { status: 400 })
|
||||||
}
|
}
|
||||||
|
const domain = new URL(request.url).hostname
|
||||||
const handle = parseHandle(id)
|
const handle = parseHandle(id)
|
||||||
|
|
||||||
// Only allow to unfollow remote users
|
// Only allow to unfollow remote users
|
||||||
|
@ -41,7 +41,7 @@ export async function handleRequest(
|
||||||
|
|
||||||
const activity = unfollow.create(connectedActor, targetActor)
|
const activity = unfollow.create(connectedActor, targetActor)
|
||||||
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
||||||
await deliverToActor(signingKey, connectedActor, targetActor, activity)
|
await deliverToActor(signingKey, connectedActor, targetActor, activity, domain)
|
||||||
await removeFollowing(db, connectedActor, targetActor)
|
await removeFollowing(db, connectedActor, targetActor)
|
||||||
|
|
||||||
const res: Relationship = {
|
const res: Relationship = {
|
||||||
|
|
|
@ -127,7 +127,7 @@ export async function handleRequest(
|
||||||
note.cc.push(targetActor.id.toString())
|
note.cc.push(targetActor.id.toString())
|
||||||
const activity = activities.create(domain, connectedActor, note)
|
const activity = activities.create(domain, connectedActor, note)
|
||||||
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
||||||
await deliverToActor(signingKey, connectedActor, targetActor, activity)
|
await deliverToActor(signingKey, connectedActor, targetActor, activity, domain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ export async function handleRequest(
|
||||||
|
|
||||||
const activity = like.create(connectedActor, new URL(obj[originalObjectIdSymbol]))
|
const activity = like.create(connectedActor, new URL(obj[originalObjectIdSymbol]))
|
||||||
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
const signingKey = await getSigningKey(userKEK, db, connectedActor)
|
||||||
await deliverToActor(signingKey, connectedActor, targetActor, activity)
|
await deliverToActor(signingKey, connectedActor, targetActor, activity, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
await insertLike(db, connectedActor, obj)
|
await insertLike(db, connectedActor, obj)
|
||||||
|
|
|
@ -50,7 +50,7 @@ export async function handleRequest(
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Delivers the announce activity to the post author.
|
// Delivers the announce activity to the post author.
|
||||||
deliverToActor(signingKey, connectedActor, targetActor, activity),
|
deliverToActor(signingKey, connectedActor, targetActor, activity, domain),
|
||||||
// Share reblogged by delivering the announce activity to followers
|
// Share reblogged by delivering the announce activity to followers
|
||||||
deliverFollowers(db, userKEK, connectedActor, activity, queue),
|
deliverFollowers(db, userKEK, connectedActor, activity, queue),
|
||||||
])
|
])
|
||||||
|
|
Ładowanie…
Reference in New Issue