]>
Commit | Line | Data |
---|---|---|
04b8c3fb C |
1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | |
3 | import { fetchVideoByUrl } from '../../../helpers/video' | |
744d0eca C |
4 | import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | |
04b8c3fb C |
6 | |
7 | export type RefreshPayload = { | |
744d0eca C |
8 | type: 'video' | 'actor' |
9 | url: string | |
04b8c3fb C |
10 | } |
11 | ||
12 | async 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 | ||
23 | export { | |
744d0eca | 24 | refreshActor, |
04b8c3fb C |
25 | refreshAPObject |
26 | } | |
27 | ||
28 | // --------------------------------------------------------------------------- | |
29 | ||
744d0eca | 30 | async 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 | |
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 | } |