-function createRemoteVideo (
- account: ActorModel,
- activity: ActivityCreate,
- videoToCreateData: VideoTorrentObject,
- channelActor: ActorModel
-) {
- logger.debug('Adding remote video %s.', videoToCreateData.id)
-
- return sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = {
- transaction: t
- }
- const videoFromDatabase = await VideoModel.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t)
- if (videoFromDatabase) return videoFromDatabase
-
- const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoToCreateData, activity.to, activity.cc)
- const video = VideoModel.build(videoData)
-
- // Don't block on request
- generateThumbnailFromUrl(video, videoToCreateData.icon)
- .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoToCreateData.id, err))
-
- const videoCreated = await video.save(sequelizeOptions)
-
- const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoToCreateData)
- if (videoFileAttributes.length === 0) {
- throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url)
- }
-
- const tasks: Bluebird<any>[] = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t }))
- await Promise.all(tasks)