2017-05-22 20:58:25 +02:00
|
|
|
import { database as db } from '../../../initializers/database'
|
2017-05-15 22:22:03 +02:00
|
|
|
import { logger } from '../../../helpers'
|
|
|
|
import { addVideoToFriends } from '../../../lib'
|
2017-06-10 22:15:25 +02:00
|
|
|
import { VideoInstance } from '../../../models'
|
2017-05-02 22:02:27 +02:00
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) {
|
2017-05-05 12:15:16 +02:00
|
|
|
db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
|
2017-05-02 22:02:27 +02:00
|
|
|
if (err) return callback(err)
|
|
|
|
|
2017-05-05 12:15:16 +02:00
|
|
|
video.transcodeVideofile(function (err) {
|
|
|
|
return callback(err, video)
|
|
|
|
})
|
2017-05-02 22:02:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
function onError (err: Error, jobId: number, video: VideoInstance, callback: () => void) {
|
2017-05-02 22:02:27 +02:00
|
|
|
logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
|
|
|
|
return callback()
|
|
|
|
}
|
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
function onSuccess (data: any, jobId: number, video: VideoInstance, callback: (err: Error) => void) {
|
2017-05-02 22:02:27 +02:00
|
|
|
logger.info('Job %d is a success.', jobId)
|
2017-05-05 12:15:16 +02:00
|
|
|
|
|
|
|
video.toAddRemoteJSON(function (err, remoteVideo) {
|
|
|
|
if (err) return callback(err)
|
|
|
|
|
|
|
|
// Now we'll add the video's meta data to our friends
|
2017-05-15 22:22:03 +02:00
|
|
|
addVideoToFriends(remoteVideo, null, callback)
|
2017-05-05 12:15:16 +02:00
|
|
|
})
|
2017-05-02 22:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 22:22:03 +02:00
|
|
|
export {
|
|
|
|
process,
|
|
|
|
onError,
|
|
|
|
onSuccess
|
|
|
|
}
|