1 import { VideoResolution } from '../../../../shared'
2 import { VideoPrivacy } from '../../../../shared/models/videos'
3 import { logger } from '../../../helpers/logger'
4 import { VideoModel } from '../../../models/video/video'
5 import { sendUpdateVideo } from '../../activitypub/send'
7 async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
8 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
9 // No video, maybe deleted?
11 logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
15 await video.transcodeOriginalVideofile(data.resolution)
20 function onError (err: Error, jobId: number) {
21 logger.error('Error when transcoding video file in job %d.', jobId, err)
22 return Promise.resolve()
25 async function onSuccess (jobId: number, video: VideoModel) {
26 if (video === undefined) return undefined
28 logger.info('Job %d is a success.', jobId)
30 // Maybe the video changed in database, refresh it
31 const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
32 // Video does not exist anymore
33 if (!videoDatabase) return undefined
35 if (video.privacy !== VideoPrivacy.PRIVATE) {
36 await sendUpdateVideo(video, undefined)
42 // ---------------------------------------------------------------------------