mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Check activities host
This commit is contained in:
parent
df66d81583
commit
5c6d985fae
37 changed files with 403 additions and 127 deletions
|
@ -1,5 +1,5 @@
|
|||
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
||||
import { getActorUrl } from '../../../helpers/activitypub'
|
||||
import { checkUrlsSameHost, getActorUrl } from '../../../helpers/activitypub'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { processAcceptActivity } from './process-accept'
|
||||
|
@ -25,11 +25,17 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, byActor: Ac
|
|||
Like: processLikeActivity
|
||||
}
|
||||
|
||||
async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) {
|
||||
async function processActivities (
|
||||
activities: Activity[],
|
||||
options: {
|
||||
signatureActor?: ActorModel
|
||||
inboxActor?: ActorModel
|
||||
outboxUrl?: string
|
||||
} = {}) {
|
||||
const actorsCache: { [ url: string ]: ActorModel } = {}
|
||||
|
||||
for (const activity of activities) {
|
||||
if (!signatureActor && [ 'Create', 'Announce', 'Like' ].indexOf(activity.type) === -1) {
|
||||
if (!options.signatureActor && [ 'Create', 'Announce', 'Like' ].indexOf(activity.type) === -1) {
|
||||
logger.error('Cannot process activity %s (type: %s) without the actor signature.', activity.id, activity.type)
|
||||
continue
|
||||
}
|
||||
|
@ -37,12 +43,17 @@ async function processActivities (activities: Activity[], signatureActor?: Actor
|
|||
const actorUrl = getActorUrl(activity.actor)
|
||||
|
||||
// When we fetch remote data, we don't have signature
|
||||
if (signatureActor && actorUrl !== signatureActor.url) {
|
||||
logger.warn('Signature mismatch between %s and %s.', actorUrl, signatureActor.url)
|
||||
if (options.signatureActor && actorUrl !== options.signatureActor.url) {
|
||||
logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, options.signatureActor.url)
|
||||
continue
|
||||
}
|
||||
|
||||
const byActor = signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
|
||||
if (options.outboxUrl && checkUrlsSameHost(options.outboxUrl, actorUrl) !== true) {
|
||||
logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', options.outboxUrl, actorUrl)
|
||||
continue
|
||||
}
|
||||
|
||||
const byActor = options.signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
|
||||
actorsCache[actorUrl] = byActor
|
||||
|
||||
const activityProcessor = processActivity[activity.type]
|
||||
|
@ -52,7 +63,7 @@ async function processActivities (activities: Activity[], signatureActor?: Actor
|
|||
}
|
||||
|
||||
try {
|
||||
await activityProcessor(activity, byActor, inboxActor)
|
||||
await activityProcessor(activity, byActor, options.inboxActor)
|
||||
} catch (err) {
|
||||
logger.warn('Cannot process activity %s.', activity.type, { err })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue