]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/jobs/handlers/video-transcoder.ts
require -> import
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / handlers / video-transcoder.ts
CommitLineData
e02643f3 1import { database as db } from '../../../initializers/database'
65fcc311
C
2import { logger } from '../../../helpers'
3import { addVideoToFriends } from '../../../lib'
227d02fe
C
4
5function process (data, callback) {
62326afb 6 db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
227d02fe
C
7 if (err) return callback(err)
8
62326afb
C
9 video.transcodeVideofile(function (err) {
10 return callback(err, video)
11 })
227d02fe
C
12 })
13}
14
62326afb 15function onError (err, jobId, video, callback) {
227d02fe
C
16 logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
17 return callback()
18}
19
62326afb 20function onSuccess (data, jobId, video, callback) {
227d02fe 21 logger.info('Job %d is a success.', jobId)
62326afb
C
22
23 video.toAddRemoteJSON(function (err, remoteVideo) {
24 if (err) return callback(err)
25
26 // Now we'll add the video's meta data to our friends
65fcc311 27 addVideoToFriends(remoteVideo, null, callback)
62326afb 28 })
227d02fe
C
29}
30
31// ---------------------------------------------------------------------------
32
65fcc311
C
33export {
34 process,
35 onError,
36 onSuccess
37}