diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-16 10:05:12 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-16 10:28:31 +0100 |
commit | a2f99b54dfdfe489e14714681189cb13c89f60a3 (patch) | |
tree | c8c06b8ebd9bd35e709882cf7cf535b11e53d481 | |
parent | 11a554cfcf96dab55681001976a553ff8e3d9dcf (diff) | |
download | PeerTube-a2f99b54dfdfe489e14714681189cb13c89f60a3.tar.gz PeerTube-a2f99b54dfdfe489e14714681189cb13c89f60a3.tar.zst PeerTube-a2f99b54dfdfe489e14714681189cb13c89f60a3.zip |
Optimize AP fetch
-rw-r--r-- | server/helpers/activitypub.ts | 6 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/actor.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 6 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 3 |
4 files changed, 13 insertions, 5 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 8b56d2d50..fe721cbac 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -187,10 +187,10 @@ function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: Contex | |||
187 | return signJsonLDObject(byActor, activity) | 187 | return signJsonLDObject(byActor, activity) |
188 | } | 188 | } |
189 | 189 | ||
190 | function getAPId (activity: string | { id: string }) { | 190 | function getAPId (object: string | { id: string }) { |
191 | if (typeof activity === 'string') return activity | 191 | if (typeof object === 'string') return object |
192 | 192 | ||
193 | return activity.id | 193 | return object.id |
194 | } | 194 | } |
195 | 195 | ||
196 | function checkUrlsSameHost (url1: string, url2: string) { | 196 | function checkUrlsSameHost (url1: string, url2: string) { |
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index 675a7b663..a4b152722 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts | |||
@@ -60,11 +60,12 @@ function isActorDeleteActivityValid (activity: any) { | |||
60 | } | 60 | } |
61 | 61 | ||
62 | function sanitizeAndCheckActorObject (actor: any) { | 62 | function sanitizeAndCheckActorObject (actor: any) { |
63 | if (!isActorTypeValid(actor.type)) return false | ||
64 | |||
63 | normalizeActor(actor) | 65 | normalizeActor(actor) |
64 | 66 | ||
65 | return exists(actor) && | 67 | return exists(actor) && |
66 | isActivityPubUrlValid(actor.id) && | 68 | isActivityPubUrlValid(actor.id) && |
67 | isActorTypeValid(actor.type) && | ||
68 | isActivityPubUrlValid(actor.inbox) && | 69 | isActivityPubUrlValid(actor.inbox) && |
69 | isActorPreferredUsernameValid(actor.preferredUsername) && | 70 | isActorPreferredUsernameValid(actor.preferredUsername) && |
70 | isActivityPubUrlValid(actor.url) && | 71 | isActivityPubUrlValid(actor.url) && |
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index ec23c705e..2619d9754 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -8,12 +8,16 @@ import { Notifier } from '../../notifier' | |||
8 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
10 | import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' | 10 | import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models' |
11 | import { getAPId } from '@server/helpers/activitypub' | ||
11 | 12 | ||
12 | async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { | 13 | async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { |
13 | const { activity, byActor: actorAnnouncer } = options | 14 | const { activity, byActor: actorAnnouncer } = options |
14 | // Only notify if it is not from a fetcher job | 15 | // Only notify if it is not from a fetcher job |
15 | const notify = options.fromFetch !== true | 16 | const notify = options.fromFetch !== true |
16 | 17 | ||
18 | // Announces on accounts are not supported | ||
19 | if (actorAnnouncer.type !== 'Application' && actorAnnouncer.type !== 'Group') return | ||
20 | |||
17 | return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify) | 21 | return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify) |
18 | } | 22 | } |
19 | 23 | ||
@@ -26,7 +30,7 @@ export { | |||
26 | // --------------------------------------------------------------------------- | 30 | // --------------------------------------------------------------------------- |
27 | 31 | ||
28 | async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { | 32 | async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) { |
29 | const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id | 33 | const objectUri = getAPId(activity.object) |
30 | 34 | ||
31 | let video: MVideoAccountLightBlacklistAllFiles | 35 | let video: MVideoAccountLightBlacklistAllFiles |
32 | let videoCreated: boolean | 36 | let videoCreated: boolean |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 70e048d6e..93f1d1c59 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -28,6 +28,9 @@ async function processCreateActivity (options: APProcessorOptions<ActivityCreate | |||
28 | } | 28 | } |
29 | 29 | ||
30 | if (activityType === 'Note') { | 30 | if (activityType === 'Note') { |
31 | // Comments will be fetched from videos | ||
32 | if (options.fromFetch) return | ||
33 | |||
31 | return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify) | 34 | return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify) |
32 | } | 35 | } |
33 | 36 | ||