diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-14 11:30:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-14 11:30:15 +0100 |
commit | 744d0eca195bce7dafeb4a958d0eb3c0046be32d (patch) | |
tree | 226c28f7fc63d1f6bf32095d7db0ef26a5b7073a /server/lib/job-queue/handlers | |
parent | bb8f7872f5a473c47a688b0c282ff34cd78a9835 (diff) | |
download | PeerTube-744d0eca195bce7dafeb4a958d0eb3c0046be32d.tar.gz PeerTube-744d0eca195bce7dafeb4a958d0eb3c0046be32d.tar.zst PeerTube-744d0eca195bce7dafeb4a958d0eb3c0046be32d.zip |
Refresh remote actors on GET enpoints
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-refresher.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts index 671b0f487..454b975fe 100644 --- a/server/lib/job-queue/handlers/activitypub-refresher.ts +++ b/server/lib/job-queue/handlers/activitypub-refresher.ts | |||
@@ -1,30 +1,33 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { fetchVideoByUrl } from '../../../helpers/video' | 3 | import { fetchVideoByUrl } from '../../../helpers/video' |
4 | import { refreshVideoIfNeeded } from '../../activitypub' | 4 | import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | ||
5 | 6 | ||
6 | export type RefreshPayload = { | 7 | export type RefreshPayload = { |
7 | videoUrl: string | 8 | type: 'video' | 'actor' |
8 | type: 'video' | 9 | url: string |
9 | } | 10 | } |
10 | 11 | ||
11 | async function refreshAPObject (job: Bull.Job) { | 12 | async function refreshAPObject (job: Bull.Job) { |
12 | const payload = job.data as RefreshPayload | 13 | const payload = job.data as RefreshPayload |
13 | 14 | ||
14 | logger.info('Processing AP refresher in job %d for video %s.', job.id, payload.videoUrl) | 15 | logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url) |
15 | 16 | ||
16 | if (payload.type === 'video') return refreshAPVideo(payload.videoUrl) | 17 | if (payload.type === 'video') return refreshVideo(payload.url) |
18 | if (payload.type === 'actor') return refreshActor(payload.url) | ||
17 | } | 19 | } |
18 | 20 | ||
19 | // --------------------------------------------------------------------------- | 21 | // --------------------------------------------------------------------------- |
20 | 22 | ||
21 | export { | 23 | export { |
24 | refreshActor, | ||
22 | refreshAPObject | 25 | refreshAPObject |
23 | } | 26 | } |
24 | 27 | ||
25 | // --------------------------------------------------------------------------- | 28 | // --------------------------------------------------------------------------- |
26 | 29 | ||
27 | async function refreshAPVideo (videoUrl: string) { | 30 | async function refreshVideo (videoUrl: string) { |
28 | const fetchType = 'all' as 'all' | 31 | const fetchType = 'all' as 'all' |
29 | const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } | 32 | const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } |
30 | 33 | ||
@@ -39,3 +42,13 @@ async function refreshAPVideo (videoUrl: string) { | |||
39 | await refreshVideoIfNeeded(refreshOptions) | 42 | await refreshVideoIfNeeded(refreshOptions) |
40 | } | 43 | } |
41 | } | 44 | } |
45 | |||
46 | async function refreshActor (actorUrl: string) { | ||
47 | const fetchType = 'all' as 'all' | ||
48 | const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl) | ||
49 | |||
50 | if (actor) { | ||
51 | await refreshActorIfNeeded(actor, fetchType) | ||
52 | } | ||
53 | |||
54 | } | ||