]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/job-queue/handlers/activitypub-refresher.ts
Update dependencies
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-refresher.ts
1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { fetchVideoByUrl } from '../../../helpers/video'
4 import { refreshVideoIfNeeded } from '../../activitypub'
5
6 export type RefreshPayload = {
7 videoUrl: string
8 type: 'video'
9 }
10
11 async function refreshAPObject (job: Bull.Job) {
12 const payload = job.data as RefreshPayload
13 logger.info('Processing AP refresher in job %d.', job.id)
14
15 if (payload.type === 'video') return refreshAPVideo(payload.videoUrl)
16 }
17
18 // ---------------------------------------------------------------------------
19
20 export {
21 refreshAPObject
22 }
23
24 // ---------------------------------------------------------------------------
25
26 async function refreshAPVideo (videoUrl: string) {
27 const fetchType = 'all' as 'all'
28 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
29
30 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
31 if (videoFromDatabase) {
32 const refreshOptions = {
33 video: videoFromDatabase,
34 fetchedType: fetchType,
35 syncParam
36 }
37
38 await refreshVideoIfNeeded(refreshOptions)
39 }
40 }