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-07-11 16:01:56 +02:00
|
|
|
function process (data: { videoUUID: string }) {
|
|
|
|
return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
|
2017-08-25 11:36:23 +02:00
|
|
|
// TODO: handle multiple resolutions
|
|
|
|
const videoFile = video.VideoFiles[0]
|
|
|
|
return video.transcodeVideofile(videoFile).then(() => video)
|
2017-05-02 22:02:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
function onError (err: Error, jobId: number) {
|
2017-07-07 18:26:12 +02:00
|
|
|
logger.error('Error when transcoding video file in job %d.', jobId, err)
|
2017-07-05 13:26:25 +02:00
|
|
|
return Promise.resolve()
|
2017-05-02 22:02:27 +02:00
|
|
|
}
|
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
function onSuccess (jobId: number, video: VideoInstance) {
|
2017-05-02 22:02:27 +02:00
|
|
|
logger.info('Job %d is a success.', jobId)
|
2017-05-05 12:15:16 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
video.toAddRemoteJSON().then(remoteVideo => {
|
2017-05-05 12:15:16 +02:00
|
|
|
// Now we'll add the video's meta data to our friends
|
2017-07-05 13:26:25 +02:00
|
|
|
return addVideoToFriends(remoteVideo, null)
|
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
|
|
|
|
}
|