]>
Commit | Line | Data |
---|---|---|
1 | import { database as db } from '../../../initializers/database' | |
2 | import { updateVideoToFriends } from '../../friends' | |
3 | import { logger } from '../../../helpers' | |
4 | import { VideoInstance } from '../../../models' | |
5 | import { VideoResolution } from '../../../../shared' | |
6 | ||
7 | async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { | |
8 | const video = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID) | |
9 | // No video, maybe deleted? | |
10 | if (!video) { | |
11 | logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) | |
12 | return undefined | |
13 | } | |
14 | ||
15 | await video.transcodeOriginalVideofile(data.resolution) | |
16 | ||
17 | return video | |
18 | } | |
19 | ||
20 | function onError (err: Error, jobId: number) { | |
21 | logger.error('Error when transcoding video file in job %d.', jobId, err) | |
22 | return Promise.resolve() | |
23 | } | |
24 | ||
25 | function onSuccess (jobId: number, video: VideoInstance) { | |
26 | if (video === undefined) return undefined | |
27 | ||
28 | logger.info('Job %d is a success.', jobId) | |
29 | ||
30 | const remoteVideo = video.toUpdateRemoteJSON() | |
31 | ||
32 | // Now we'll add the video's meta data to our friends | |
33 | return updateVideoToFriends(remoteVideo, null) | |
34 | } | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | export { | |
39 | process, | |
40 | onError, | |
41 | onSuccess | |
42 | } |