]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Optimize AP fetch
authorChocobozzz <me@florianbigard.com>
Tue, 16 Nov 2021 09:05:12 +0000 (10:05 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 16 Nov 2021 09:28:31 +0000 (10:28 +0100)
server/helpers/activitypub.ts
server/helpers/custom-validators/activitypub/actor.ts
server/lib/activitypub/process/process-announce.ts
server/lib/activitypub/process/process-create.ts

index 8b56d2d5099bd78070821ab150210c1b3a49b57f..fe721cbac1f01e351d157dd8a7d965c45ffd8c1d 100644 (file)
@@ -187,10 +187,10 @@ function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: Contex
   return signJsonLDObject(byActor, activity)
 }
 
-function getAPId (activity: string | { id: string }) {
-  if (typeof activity === 'string') return activity
+function getAPId (object: string | { id: string }) {
+  if (typeof object === 'string') return object
 
-  return activity.id
+  return object.id
 }
 
 function checkUrlsSameHost (url1: string, url2: string) {
index 675a7b66324e2d40781dde86faaf126768b76cf2..a4b1527221031092e678aab66406766f6a8449db 100644 (file)
@@ -60,11 +60,12 @@ function isActorDeleteActivityValid (activity: any) {
 }
 
 function sanitizeAndCheckActorObject (actor: any) {
+  if (!isActorTypeValid(actor.type)) return false
+
   normalizeActor(actor)
 
   return exists(actor) &&
     isActivityPubUrlValid(actor.id) &&
-    isActorTypeValid(actor.type) &&
     isActivityPubUrlValid(actor.inbox) &&
     isActorPreferredUsernameValid(actor.preferredUsername) &&
     isActivityPubUrlValid(actor.url) &&
index ec23c705e5e9d037a1ebb57461d085c9a1da6a96..2619d9754f70906f87e5ed3eb9a034d3a29f5e01 100644 (file)
@@ -8,12 +8,16 @@ import { Notifier } from '../../notifier'
 import { logger } from '../../../helpers/logger'
 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
 import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
+import { getAPId } from '@server/helpers/activitypub'
 
 async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
   const { activity, byActor: actorAnnouncer } = options
   // Only notify if it is not from a fetcher job
   const notify = options.fromFetch !== true
 
+  // Announces on accounts are not supported
+  if (actorAnnouncer.type !== 'Application' && actorAnnouncer.type !== 'Group') return
+
   return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify)
 }
 
@@ -26,7 +30,7 @@ export {
 // ---------------------------------------------------------------------------
 
 async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) {
-  const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
+  const objectUri = getAPId(activity.object)
 
   let video: MVideoAccountLightBlacklistAllFiles
   let videoCreated: boolean
index 70e048d6e488964b43497f192d3f5c34ed92b338..93f1d1c59d52aee8f44d67efe4c2cf513e444c38 100644 (file)
@@ -28,6 +28,9 @@ async function processCreateActivity (options: APProcessorOptions<ActivityCreate
   }
 
   if (activityType === 'Note') {
+    // Comments will be fetched from videos
+    if (options.fromFetch) return
+
     return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify)
   }