mirror of https://github.com/Chocobozzz/PeerTube
Optimize AP fetch
parent
11a554cfcf
commit
a2f99b54df
|
@ -187,10 +187,10 @@ function buildSignedActivity <T> (byActor: MActor, data: T, contextType?: Contex
|
||||||
return signJsonLDObject(byActor, activity)
|
return signJsonLDObject(byActor, activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAPId (activity: string | { id: string }) {
|
function getAPId (object: string | { id: string }) {
|
||||||
if (typeof activity === 'string') return activity
|
if (typeof object === 'string') return object
|
||||||
|
|
||||||
return activity.id
|
return object.id
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUrlsSameHost (url1: string, url2: string) {
|
function checkUrlsSameHost (url1: string, url2: string) {
|
||||||
|
|
|
@ -60,11 +60,12 @@ function isActorDeleteActivityValid (activity: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeAndCheckActorObject (actor: any) {
|
function sanitizeAndCheckActorObject (actor: any) {
|
||||||
|
if (!isActorTypeValid(actor.type)) return false
|
||||||
|
|
||||||
normalizeActor(actor)
|
normalizeActor(actor)
|
||||||
|
|
||||||
return exists(actor) &&
|
return exists(actor) &&
|
||||||
isActivityPubUrlValid(actor.id) &&
|
isActivityPubUrlValid(actor.id) &&
|
||||||
isActorTypeValid(actor.type) &&
|
|
||||||
isActivityPubUrlValid(actor.inbox) &&
|
isActivityPubUrlValid(actor.inbox) &&
|
||||||
isActorPreferredUsernameValid(actor.preferredUsername) &&
|
isActorPreferredUsernameValid(actor.preferredUsername) &&
|
||||||
isActivityPubUrlValid(actor.url) &&
|
isActivityPubUrlValid(actor.url) &&
|
||||||
|
|
|
@ -8,12 +8,16 @@ import { Notifier } from '../../notifier'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
|
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
|
||||||
import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
|
import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
|
||||||
|
import { getAPId } from '@server/helpers/activitypub'
|
||||||
|
|
||||||
async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
|
async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
|
||||||
const { activity, byActor: actorAnnouncer } = options
|
const { activity, byActor: actorAnnouncer } = options
|
||||||
// Only notify if it is not from a fetcher job
|
// Only notify if it is not from a fetcher job
|
||||||
const notify = options.fromFetch !== true
|
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)
|
return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity, notify)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +30,7 @@ export {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) {
|
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 video: MVideoAccountLightBlacklistAllFiles
|
||||||
let videoCreated: boolean
|
let videoCreated: boolean
|
||||||
|
|
|
@ -28,6 +28,9 @@ async function processCreateActivity (options: APProcessorOptions<ActivityCreate
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activityType === 'Note') {
|
if (activityType === 'Note') {
|
||||||
|
// Comments will be fetched from videos
|
||||||
|
if (options.fromFetch) return
|
||||||
|
|
||||||
return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify)
|
return retryTransactionWrapper(processCreateVideoComment, activity, byActor, notify)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue