]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/handlers/video-file-transcoder.ts
Use async/await in controllers
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / handlers / video-file-transcoder.ts
CommitLineData
e02643f3 1import { database as db } from '../../../initializers/database'
40298b02 2import { updateVideoToFriends } from '../../friends'
65fcc311 3import { logger } from '../../../helpers'
69818c93 4import { VideoInstance } from '../../../models'
40298b02 5import { VideoResolution } from '../../../../shared'
227d02fe 6
031094f7 7function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
0a6658fd 8 return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
031094f7
C
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
40298b02 15 return video.transcodeOriginalVideofile(data.resolution).then(() => video)
227d02fe
C
16 })
17}
18
6fcd19ba 19function 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
6fcd19ba 24function onSuccess (jobId: number, video: VideoInstance) {
031094f7
C
25 if (video === undefined) return undefined
26
227d02fe 27 logger.info('Job %d is a success.', jobId)
62326afb 28
40298b02
C
29 const remoteVideo = video.toUpdateRemoteJSON()
30
31 // Now we'll add the video's meta data to our friends
32 return updateVideoToFriends(remoteVideo, null)
227d02fe
C
33}
34
35// ---------------------------------------------------------------------------
36
65fcc311
C
37export {
38 process,
39 onError,
40 onSuccess
41}