2017-05-22 14:58:25 -04:00
|
|
|
import { database as db } from '../../../initializers/database'
|
2017-10-02 06:20:26 -04:00
|
|
|
import { updateVideoToFriends } from '../../friends'
|
2017-05-15 16:22:03 -04:00
|
|
|
import { logger } from '../../../helpers'
|
2017-06-10 16:15:25 -04:00
|
|
|
import { VideoInstance } from '../../../models'
|
2017-10-02 06:20:26 -04:00
|
|
|
import { VideoResolution } from '../../../../shared'
|
2017-05-02 16:02:27 -04:00
|
|
|
|
2017-10-25 10:03:33 -04:00
|
|
|
async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
|
|
|
|
const video = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(data.videoUUID)
|
|
|
|
// No video, maybe deleted?
|
|
|
|
if (!video) {
|
|
|
|
logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
await video.transcodeOriginalVideofile(data.resolution)
|
|
|
|
|
|
|
|
return video
|
2017-05-02 16:02:27 -04:00
|
|
|
}
|
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
function onError (err: Error, jobId: number) {
|
2017-07-07 12:26:12 -04:00
|
|
|
logger.error('Error when transcoding video file in job %d.', jobId, err)
|
2017-07-05 07:26:25 -04:00
|
|
|
return Promise.resolve()
|
2017-05-02 16:02:27 -04:00
|
|
|
}
|
|
|
|
|
2017-10-26 08:22:37 -04:00
|
|
|
async function onSuccess (jobId: number, video: VideoInstance) {
|
2017-10-17 09:37:40 -04:00
|
|
|
if (video === undefined) return undefined
|
|
|
|
|
2017-05-02 16:02:27 -04:00
|
|
|
logger.info('Job %d is a success.', jobId)
|
2017-05-05 06:15:16 -04:00
|
|
|
|
2017-10-26 08:22:37 -04:00
|
|
|
// Maybe the video changed in database, refresh it
|
|
|
|
const videoDatabase = await db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(video.uuid)
|
|
|
|
// Video does not exist anymore
|
|
|
|
if (!videoDatabase) return undefined
|
|
|
|
|
|
|
|
const remoteVideo = videoDatabase.toUpdateRemoteJSON()
|
2017-10-02 06:20:26 -04:00
|
|
|
|
|
|
|
// Now we'll add the video's meta data to our friends
|
2017-10-26 08:22:37 -04:00
|
|
|
await updateVideoToFriends(remoteVideo, null)
|
|
|
|
|
2017-10-26 09:16:05 -04:00
|
|
|
return undefined
|
2017-05-02 16:02:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
export {
|
|
|
|
process,
|
|
|
|
onError,
|
|
|
|
onSuccess
|
|
|
|
}
|