1
0
Fork 0
peertube/server/lib/jobs/handlers/video-file-transcoder.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-05-22 14:58:25 -04:00
import { database as db } from '../../../initializers/database'
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'
import { VideoResolution } from '../../../../shared'
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
}
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)
return Promise.resolve()
}
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
logger.info('Job %d is a success.', jobId)
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()
// 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-15 16:22:03 -04:00
export {
process,
onError,
onSuccess
}