diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-24 15:36:50 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | 687d638c2bee0d223f206168173b1b95adbad983 (patch) | |
tree | 957741b0ba704562a233181510bb8fda0102c8a5 /server/lib | |
parent | f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d (diff) | |
download | PeerTube-687d638c2bee0d223f206168173b1b95adbad983.tar.gz PeerTube-687d638c2bee0d223f206168173b1b95adbad983.tar.zst PeerTube-687d638c2bee0d223f206168173b1b95adbad983.zip |
Fetch outbox when searching an actor
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 22e1c9f19..1657262d7 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -36,8 +36,13 @@ function setAsyncActorKeys (actor: ActorModel) { | |||
36 | }) | 36 | }) |
37 | } | 37 | } |
38 | 38 | ||
39 | async function getOrCreateActorAndServerAndModel (activityActor: string | ActivityPubActor, recurseIfNeeded = true) { | 39 | async function getOrCreateActorAndServerAndModel ( |
40 | activityActor: string | ActivityPubActor, | ||
41 | recurseIfNeeded = true, | ||
42 | updateCollections = false | ||
43 | ) { | ||
40 | const actorUrl = getActorUrl(activityActor) | 44 | const actorUrl = getActorUrl(activityActor) |
45 | let created = false | ||
41 | 46 | ||
42 | let actor = await ActorModel.loadByUrl(actorUrl) | 47 | let actor = await ActorModel.loadByUrl(actorUrl) |
43 | // Orphan actor (not associated to an account of channel) so recreate it | 48 | // Orphan actor (not associated to an account of channel) so recreate it |
@@ -68,15 +73,21 @@ async function getOrCreateActorAndServerAndModel (activityActor: string | Activi | |||
68 | } | 73 | } |
69 | 74 | ||
70 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) | 75 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) |
76 | created = true | ||
71 | } | 77 | } |
72 | 78 | ||
73 | if (actor.Account) actor.Account.Actor = actor | 79 | if (actor.Account) actor.Account.Actor = actor |
74 | if (actor.VideoChannel) actor.VideoChannel.Actor = actor | 80 | if (actor.VideoChannel) actor.VideoChannel.Actor = actor |
75 | 81 | ||
76 | actor = await retryTransactionWrapper(refreshActorIfNeeded, actor) | 82 | const { actor: actorRefreshed, refreshed } = await retryTransactionWrapper(refreshActorIfNeeded, actor) |
77 | if (!actor) throw new Error('Actor ' + actor.url + ' does not exist anymore.') | 83 | if (!actorRefreshed) throw new Error('Actor ' + actorRefreshed.url + ' does not exist anymore.') |
78 | 84 | ||
79 | return actor | 85 | if ((created === true || refreshed === true) && updateCollections === true) { |
86 | const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' } | ||
87 | await JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }) | ||
88 | } | ||
89 | |||
90 | return actorRefreshed | ||
80 | } | 91 | } |
81 | 92 | ||
82 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { | 93 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { |
@@ -359,8 +370,8 @@ async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResu | |||
359 | return videoChannelCreated | 370 | return videoChannelCreated |
360 | } | 371 | } |
361 | 372 | ||
362 | async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> { | 373 | async function refreshActorIfNeeded (actor: ActorModel): Promise<{ actor: ActorModel, refreshed: boolean }> { |
363 | if (!actor.isOutdated()) return actor | 374 | if (!actor.isOutdated()) return { actor, refreshed: false } |
364 | 375 | ||
365 | try { | 376 | try { |
366 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) | 377 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) |
@@ -369,12 +380,12 @@ async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> { | |||
369 | if (statusCode === 404) { | 380 | if (statusCode === 404) { |
370 | logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url) | 381 | logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url) |
371 | actor.Account ? actor.Account.destroy() : actor.VideoChannel.destroy() | 382 | actor.Account ? actor.Account.destroy() : actor.VideoChannel.destroy() |
372 | return undefined | 383 | return { actor: undefined, refreshed: false } |
373 | } | 384 | } |
374 | 385 | ||
375 | if (result === undefined) { | 386 | if (result === undefined) { |
376 | logger.warn('Cannot fetch remote actor in refresh actor.') | 387 | logger.warn('Cannot fetch remote actor in refresh actor.') |
377 | return actor | 388 | return { actor, refreshed: false } |
378 | } | 389 | } |
379 | 390 | ||
380 | return sequelizeTypescript.transaction(async t => { | 391 | return sequelizeTypescript.transaction(async t => { |
@@ -403,10 +414,10 @@ async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> { | |||
403 | await actor.VideoChannel.save({ transaction: t }) | 414 | await actor.VideoChannel.save({ transaction: t }) |
404 | } | 415 | } |
405 | 416 | ||
406 | return actor | 417 | return { refreshed: true, actor } |
407 | }) | 418 | }) |
408 | } catch (err) { | 419 | } catch (err) { |
409 | logger.warn('Cannot refresh actor.', { err }) | 420 | logger.warn('Cannot refresh actor.', { err }) |
410 | return actor | 421 | return { actor, refreshed: false } |
411 | } | 422 | } |
412 | } | 423 | } |