2017-05-22 18:58:25 +00:00
|
|
|
import { database as db } from '../../../initializers/database'
|
2017-10-02 10:20:26 +00:00
|
|
|
import { updateVideoToFriends } from '../../friends'
|
2017-05-15 20:22:03 +00:00
|
|
|
import { logger } from '../../../helpers'
|
2017-06-10 20:15:25 +00:00
|
|
|
import { VideoInstance } from '../../../models'
|
2017-10-02 10:20:26 +00:00
|
|
|
import { VideoResolution } from '../../../../shared'
|
2017-05-02 20:02:27 +00:00
|
|
|
|
2017-10-02 10:20:26 +00:00
|
|
|
function process (data: { videoUUID: string, resolution: VideoResolution }) {
|
2017-07-11 14:01:56 +00:00
|
|
|
return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID).then(video => {
|
2017-10-02 10:20:26 +00:00
|
|
|
return video.transcodeOriginalVideofile(data.resolution).then(() => video)
|
2017-05-02 20:02:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-05 11:26:25 +00:00
|
|
|
function onError (err: Error, jobId: number) {
|
2017-07-07 16:26:12 +00:00
|
|
|
logger.error('Error when transcoding video file in job %d.', jobId, err)
|
2017-07-05 11:26:25 +00:00
|
|
|
return Promise.resolve()
|
2017-05-02 20:02:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 11:26:25 +00:00
|
|
|
function onSuccess (jobId: number, video: VideoInstance) {
|
2017-05-02 20:02:27 +00:00
|
|
|
logger.info('Job %d is a success.', jobId)
|
2017-05-05 10:15:16 +00:00
|
|
|
|
2017-10-02 10:20:26 +00:00
|
|
|
const remoteVideo = video.toUpdateRemoteJSON()
|
|
|
|
|
|
|
|
// Now we'll add the video's meta data to our friends
|
|
|
|
return updateVideoToFriends(remoteVideo, null)
|
2017-05-02 20:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 20:22:03 +00:00
|
|
|
export {
|
|
|
|
process,
|
|
|
|
onError,
|
|
|
|
onSuccess
|
|
|
|
}
|