]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-refresher.ts
don't notify prior to scheduled update
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-refresher.ts
CommitLineData
04b8c3fb
C
1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger'
3import { fetchVideoByUrl } from '../../../helpers/video'
744d0eca
C
4import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub'
5import { ActorModel } from '../../../models/activitypub/actor'
04b8c3fb
C
6
7export type RefreshPayload = {
744d0eca
C
8 type: 'video' | 'actor'
9 url: string
04b8c3fb
C
10}
11
12async function refreshAPObject (job: Bull.Job) {
13 const payload = job.data as RefreshPayload
74577825 14
744d0eca 15 logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
04b8c3fb 16
744d0eca
C
17 if (payload.type === 'video') return refreshVideo(payload.url)
18 if (payload.type === 'actor') return refreshActor(payload.url)
04b8c3fb
C
19}
20
21// ---------------------------------------------------------------------------
22
23export {
744d0eca 24 refreshActor,
04b8c3fb
C
25 refreshAPObject
26}
27
28// ---------------------------------------------------------------------------
29
744d0eca 30async function refreshVideo (videoUrl: string) {
04b8c3fb
C
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}
744d0eca
C
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}