diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-24 11:04:02 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d (patch) | |
tree | 1b2f8a578b2d35138ac326d65674a9c9d740e8c9 /server/lib | |
parent | aa55a4da422330fe2816f1764b64f6607a0ca4aa (diff) | |
download | PeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.tar.gz PeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.tar.zst PeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.zip |
Search video channel handle/uri
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 38 |
1 files changed, 27 insertions, 11 deletions
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 | |||
48 | 48 | ||
49 | // We don't have this actor in our database, fetch it on remote | 49 | // We don't have this actor in our database, fetch it on remote |
50 | if (!actor) { | 50 | if (!actor) { |
51 | const result = await fetchRemoteActor(actorUrl) | 51 | const { result } = await fetchRemoteActor(actorUrl) |
52 | if (result === undefined) throw new Error('Cannot fetch remote actor.') | 52 | if (result === undefined) throw new Error('Cannot fetch remote actor.') |
53 | 53 | ||
54 | // Create the attributed to actor | 54 | // Create the attributed to actor |
@@ -70,7 +70,13 @@ async function getOrCreateActorAndServerAndModel (activityActor: string | Activi | |||
70 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) | 70 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) |
71 | } | 71 | } |
72 | 72 | ||
73 | return retryTransactionWrapper(refreshActorIfNeeded, actor) | 73 | if (actor.Account) actor.Account.Actor = actor |
74 | if (actor.VideoChannel) actor.VideoChannel.Actor = actor | ||
75 | |||
76 | actor = await retryTransactionWrapper(refreshActorIfNeeded, actor) | ||
77 | if (!actor) throw new Error('Actor ' + actor.url + ' does not exist anymore.') | ||
78 | |||
79 | return actor | ||
74 | } | 80 | } |
75 | 81 | ||
76 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { | 82 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { |
@@ -264,7 +270,7 @@ type FetchRemoteActorResult = { | |||
264 | avatarName?: string | 270 | avatarName?: string |
265 | attributedTo: ActivityPubAttributedTo[] | 271 | attributedTo: ActivityPubAttributedTo[] |
266 | } | 272 | } |
267 | async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResult> { | 273 | async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: number, result: FetchRemoteActorResult }> { |
268 | const options = { | 274 | const options = { |
269 | uri: actorUrl, | 275 | uri: actorUrl, |
270 | method: 'GET', | 276 | method: 'GET', |
@@ -281,7 +287,7 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu | |||
281 | 287 | ||
282 | if (isActorObjectValid(actorJSON) === false) { | 288 | if (isActorObjectValid(actorJSON) === false) { |
283 | logger.debug('Remote actor JSON is not valid.', { actorJSON: actorJSON }) | 289 | logger.debug('Remote actor JSON is not valid.', { actorJSON: actorJSON }) |
284 | return undefined | 290 | return { result: undefined, statusCode: requestResult.response.statusCode } |
285 | } | 291 | } |
286 | 292 | ||
287 | const followersCount = await fetchActorTotalItems(actorJSON.followers) | 293 | const followersCount = await fetchActorTotalItems(actorJSON.followers) |
@@ -307,12 +313,15 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu | |||
307 | 313 | ||
308 | const name = actorJSON.name || actorJSON.preferredUsername | 314 | const name = actorJSON.name || actorJSON.preferredUsername |
309 | return { | 315 | return { |
310 | actor, | 316 | statusCode: requestResult.response.statusCode, |
311 | name, | 317 | result: { |
312 | avatarName, | 318 | actor, |
313 | summary: actorJSON.summary, | 319 | name, |
314 | support: actorJSON.support, | 320 | avatarName, |
315 | attributedTo: actorJSON.attributedTo | 321 | summary: actorJSON.summary, |
322 | support: actorJSON.support, | ||
323 | attributedTo: actorJSON.attributedTo | ||
324 | } | ||
316 | } | 325 | } |
317 | } | 326 | } |
318 | 327 | ||
@@ -355,7 +364,14 @@ async function refreshActorIfNeeded (actor: ActorModel): Promise<ActorModel> { | |||
355 | 364 | ||
356 | try { | 365 | try { |
357 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) | 366 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername + '@' + actor.getHost()) |
358 | const result = await fetchRemoteActor(actorUrl) | 367 | const { result, statusCode } = await fetchRemoteActor(actorUrl) |
368 | |||
369 | if (statusCode === 404) { | ||
370 | logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url) | ||
371 | actor.Account ? actor.Account.destroy() : actor.VideoChannel.destroy() | ||
372 | return undefined | ||
373 | } | ||
374 | |||
359 | if (result === undefined) { | 375 | if (result === undefined) { |
360 | logger.warn('Cannot fetch remote actor in refresh actor.') | 376 | logger.warn('Cannot fetch remote actor in refresh actor.') |
361 | return actor | 377 | return actor |