-function insertIntoDB (parameters: {
- video: VideoModel,
- thumbnailModel: ThumbnailModel,
- previewModel: ThumbnailModel,
- videoChannel: VideoChannelModel,
- tags: string[],
- videoImportAttributes: Partial<VideoImportModel>,
- user: UserModel
-}): Bluebird<VideoImportModel> {
- const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
-
- return sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = { transaction: t }
-
- // Save video object in database
- const videoCreated = await video.save(sequelizeOptions)
- videoCreated.VideoChannel = videoChannel
-
- if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
- if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
-
- await autoBlacklistVideoIfNeeded({ video, user, isRemote: false, isNew: true, transaction: t })
-
- // Set tags to the video
- if (tags) {
- const tagInstances = await TagModel.findOrCreateTags(tags, t)
-
- await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
- videoCreated.Tags = tagInstances
- } else {
- videoCreated.Tags = []
- }