PeerTube/server/lib/jobs/handlers/video-transcoder.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

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-06-10 22:15:25 +02:00
function process (data: { id: string }, callback: (err: Error, videoInstance?: VideoInstance) => void) {
db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
if (err) return callback(err)
video.transcodeVideofile(function (err) {
return callback(err, video)
})
})
}
2017-06-10 22:15:25 +02:00
function onError (err: Error, jobId: number, video: VideoInstance, callback: () => void) {
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) {
logger.info('Job %d is a success.', jobId)
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-15 22:22:03 +02:00
export {
process,
onError,
onSuccess
}