]>
Commit | Line | Data |
---|---|---|
04b8c3fb C |
1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | |
3 | import { fetchVideoByUrl } from '../../../helpers/video' | |
9f79ade6 | 4 | import { refreshActorIfNeeded, refreshVideoIfNeeded, refreshVideoPlaylistIfNeeded } from '../../activitypub' |
744d0eca | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
9f79ade6 | 6 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' |
04b8c3fb C |
7 | |
8 | export type RefreshPayload = { | |
9f79ade6 | 9 | type: 'video' | 'video-playlist' | 'actor' |
744d0eca | 10 | url: string |
04b8c3fb C |
11 | } |
12 | ||
13 | async function refreshAPObject (job: Bull.Job) { | |
14 | const payload = job.data as RefreshPayload | |
74577825 | 15 | |
744d0eca | 16 | logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url) |
04b8c3fb | 17 | |
744d0eca | 18 | if (payload.type === 'video') return refreshVideo(payload.url) |
9f79ade6 | 19 | if (payload.type === 'video-playlist') return refreshVideoPlaylist(payload.url) |
744d0eca | 20 | if (payload.type === 'actor') return refreshActor(payload.url) |
04b8c3fb C |
21 | } |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | export { | |
26 | refreshAPObject | |
27 | } | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
744d0eca | 31 | async function refreshVideo (videoUrl: string) { |
04b8c3fb C |
32 | const fetchType = 'all' as 'all' |
33 | const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } | |
34 | ||
35 | const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) | |
36 | if (videoFromDatabase) { | |
37 | const refreshOptions = { | |
38 | video: videoFromDatabase, | |
39 | fetchedType: fetchType, | |
40 | syncParam | |
41 | } | |
42 | ||
43 | await refreshVideoIfNeeded(refreshOptions) | |
44 | } | |
45 | } | |
744d0eca C |
46 | |
47 | async function refreshActor (actorUrl: string) { | |
48 | const fetchType = 'all' as 'all' | |
49 | const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl) | |
50 | ||
51 | if (actor) { | |
52 | await refreshActorIfNeeded(actor, fetchType) | |
53 | } | |
9f79ade6 C |
54 | } |
55 | ||
56 | async function refreshVideoPlaylist (playlistUrl: string) { | |
57 | const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl) | |
744d0eca | 58 | |
9f79ade6 C |
59 | if (playlist) { |
60 | await refreshVideoPlaylistIfNeeded(playlist) | |
61 | } | |
744d0eca | 62 | } |