From f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Aug 2018 11:04:02 +0200 Subject: Search video channel handle/uri --- server/lib/activitypub/actor.ts | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 9922229d2..22e1c9f19 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -48,7 +48,7 @@ async function getOrCreateActorAndServerAndModel (activityActor: string | Activi // We don't have this actor in our database, fetch it on remote if (!actor) { - const result = await fetchRemoteActor(actorUrl) + const { result } = await fetchRemoteActor(actorUrl) if (result === undefined) throw new Error('Cannot fetch remote actor.') // Create the attributed to actor @@ -70,7 +70,13 @@ async function getOrCreateActorAndServerAndModel (activityActor: string | Activi actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) } - return retryTransactionWrapper(refreshActorIfNeeded, actor) + if (actor.Account) actor.Account.Actor = actor + if (actor.VideoChannel) actor.VideoChannel.Actor = actor + + actor = await retryTransactionWrapper(refreshActorIfNeeded, actor) + if (!actor) throw new Error('Actor ' + actor.url + ' does not exist anymore.') + + return actor } function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { @@ -264,7 +270,7 @@ type FetchRemoteActorResult = { avatarName?: string attributedTo: ActivityPubAttributedTo[] } -async function fetchRemoteActor (actorUrl: string): Promise { +async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: number, result: FetchRemoteActorResult }> { const options = { uri: actorUrl, method: 'GET', @@ -281,7 +287,7 @@ async function fetchRemoteActor (actorUrl: string): Promise { try { const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) - const result = await fetchRemoteActor(actorUrl) + const { result, statusCode } = await fetchRemoteActor(actorUrl) + + if (statusCode === 404) { + logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url) + actor.Account ? actor.Account.destroy() : actor.VideoChannel.destroy() + return undefined + } + if (result === undefined) { logger.warn('Cannot fetch remote actor in refresh actor.') return actor -- cgit v1.2.3