aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/activitypub-refresher.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/activitypub-refresher.ts')
-rw-r--r--server/lib/job-queue/handlers/activitypub-refresher.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts
new file mode 100644
index 000000000..454b975fe
--- /dev/null
+++ b/server/lib/job-queue/handlers/activitypub-refresher.ts
@@ -0,0 +1,54 @@
1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger'
3import { fetchVideoByUrl } from '../../../helpers/video'
4import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub'
5import { ActorModel } from '../../../models/activitypub/actor'
6
7export type RefreshPayload = {
8 type: 'video' | 'actor'
9 url: string
10}
11
12async function refreshAPObject (job: Bull.Job) {
13 const payload = job.data as RefreshPayload
14
15 logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
16
17 if (payload.type === 'video') return refreshVideo(payload.url)
18 if (payload.type === 'actor') return refreshActor(payload.url)
19}
20
21// ---------------------------------------------------------------------------
22
23export {
24 refreshActor,
25 refreshAPObject
26}
27
28// ---------------------------------------------------------------------------
29
30async function refreshVideo (videoUrl: string) {
31 const fetchType = 'all' as 'all'
32 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
33
34 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
35 if (videoFromDatabase) {
36 const refreshOptions = {
37 video: videoFromDatabase,
38 fetchedType: fetchType,
39 syncParam
40 }
41
42 await refreshVideoIfNeeded(refreshOptions)
43 }
44}
45
46async 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}