]>
Commit | Line | Data |
---|---|---|
571389d4 | 1 | import { VideoResolution } from '../../../../shared' |
65fcc311 | 2 | import { logger } from '../../../helpers' |
3fd3ab2d C |
3 | import { VideoModel } from '../../../models/video/video' |
4 | import { sendUpdateVideo } from '../../activitypub/send' | |
227d02fe | 5 | |
f5028693 | 6 | async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { |
3fd3ab2d | 7 | const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) |
f5028693 C |
8 | // No video, maybe deleted? |
9 | if (!video) { | |
10 | logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) | |
11 | return undefined | |
12 | } | |
13 | ||
14 | await video.transcodeOriginalVideofile(data.resolution) | |
15 | ||
16 | return video | |
227d02fe C |
17 | } |
18 | ||
6fcd19ba | 19 | function onError (err: Error, jobId: number) { |
ad0997ad | 20 | logger.error('Error when transcoding video file in job %d.', jobId, err) |
6fcd19ba | 21 | return Promise.resolve() |
227d02fe C |
22 | } |
23 | ||
3fd3ab2d | 24 | async function onSuccess (jobId: number, video: VideoModel) { |
031094f7 C |
25 | if (video === undefined) return undefined |
26 | ||
227d02fe | 27 | logger.info('Job %d is a success.', jobId) |
62326afb | 28 | |
4077df72 | 29 | // Maybe the video changed in database, refresh it |
3fd3ab2d | 30 | const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) |
4077df72 C |
31 | // Video does not exist anymore |
32 | if (!videoDatabase) return undefined | |
33 | ||
571389d4 | 34 | await sendUpdateVideo(video, undefined) |
4077df72 | 35 | |
7ff7802a | 36 | return undefined |
227d02fe C |
37 | } |
38 | ||
39 | // --------------------------------------------------------------------------- | |
40 | ||
65fcc311 C |
41 | export { |
42 | process, | |
43 | onError, | |
44 | onSuccess | |
45 | } |