]>
Commit | Line | Data |
---|---|---|
227d02fe C |
1 | 'use strict' |
2 | ||
3 | const db = require('../../../initializers/database') | |
4 | const logger = require('../../../helpers/logger') | |
62326afb | 5 | const friends = require('../../../lib/friends') |
227d02fe C |
6 | |
7 | const VideoTranscoderHandler = { | |
8 | process, | |
9 | onError, | |
10 | onSuccess | |
11 | } | |
12 | ||
13 | // --------------------------------------------------------------------------- | |
14 | ||
15 | function process (data, callback) { | |
62326afb | 16 | db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { |
227d02fe C |
17 | if (err) return callback(err) |
18 | ||
62326afb C |
19 | video.transcodeVideofile(function (err) { |
20 | return callback(err, video) | |
21 | }) | |
227d02fe C |
22 | }) |
23 | } | |
24 | ||
62326afb | 25 | function onError (err, jobId, video, callback) { |
227d02fe C |
26 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) |
27 | return callback() | |
28 | } | |
29 | ||
62326afb | 30 | function onSuccess (data, jobId, video, callback) { |
227d02fe | 31 | logger.info('Job %d is a success.', jobId) |
62326afb C |
32 | |
33 | video.toAddRemoteJSON(function (err, remoteVideo) { | |
34 | if (err) return callback(err) | |
35 | ||
36 | // Now we'll add the video's meta data to our friends | |
37 | friends.addVideoToFriends(remoteVideo, null, callback) | |
38 | }) | |
227d02fe C |
39 | } |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | module.exports = VideoTranscoderHandler |