2017-11-10 17:27:49 +01:00
|
|
|
import { VideoResolution } from '../../../../shared'
|
2017-12-19 10:34:56 +01:00
|
|
|
import { VideoPrivacy } from '../../../../shared/models/videos'
|
2017-12-28 11:16:08 +01:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-12-12 17:53:50 +01:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
|
|
|
import { sendUpdateVideo } from '../../activitypub/send'
|
2017-05-02 22:02:27 +02:00
|
|
|
|
2017-10-25 16:03:33 +02:00
|
|
|
async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) {
|
2017-12-12 17:53:50 +01:00
|
|
|
const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
|
2017-10-25 16:03:33 +02:00
|
|
|
// 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 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-12-12 17:53:50 +01:00
|
|
|
async function onSuccess (jobId: number, video: VideoModel) {
|
2017-10-17 15:37:40 +02:00
|
|
|
if (video === undefined) return undefined
|
|
|
|
|
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-10-26 14:22:37 +02:00
|
|
|
// Maybe the video changed in database, refresh it
|
2017-12-12 17:53:50 +01:00
|
|
|
const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
|
2017-10-26 14:22:37 +02:00
|
|
|
// Video does not exist anymore
|
|
|
|
if (!videoDatabase) return undefined
|
|
|
|
|
2017-12-19 10:34:56 +01:00
|
|
|
if (video.privacy !== VideoPrivacy.PRIVATE) {
|
|
|
|
await sendUpdateVideo(video, undefined)
|
|
|
|
}
|
2017-10-26 14:22:37 +02:00
|
|
|
|
2017-10-26 15:16:05 +02:00
|
|
|
return undefined
|
2017-05-02 22:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 22:22:03 +02:00
|
|
|
export {
|
|
|
|
process,
|
|
|
|
onError,
|
|
|
|
onSuccess
|
|
|
|
}
|