import * as express from 'express'
import * as magnetUtil from 'magnet-uri'
-import 'multer'
import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
import { MIMETYPES } from '../../../initializers/constants'
import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import {
- MChannelActorAccountDefault,
+ MChannelAccountDefault,
MThumbnail,
MUser,
+ MVideoAccountDefault,
+ MVideoTag,
MVideoThumbnailAccountDefault,
MVideoWithBlacklistLight
} from '@server/typings/models'
-import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
+import { MVideoImport, MVideoImportFormattable } from '@server/typings/models/video/video-import'
const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router()
category: body.category || importData.category,
licence: body.licence || importData.licence,
language: body.language || undefined,
- commentsEnabled: body.commentsEnabled || true,
- downloadEnabled: body.downloadEnabled || true,
+ commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true"
+ downloadEnabled: body.downloadEnabled !== false,
waitTranscoding: body.waitTranscoding || false,
state: VideoState.TO_IMPORT,
nsfw: body.nsfw || importData.nsfw || false,
video: MVideoThumbnailAccountDefault,
thumbnailModel: MThumbnail,
previewModel: MThumbnail,
- videoChannel: MChannelActorAccountDefault,
+ videoChannel: MChannelAccountDefault,
tags: string[],
videoImportAttributes: Partial<MVideoImport>,
user: MUser
-}): Bluebird<MVideoImportVideo> {
+}): Bluebird<MVideoImportFormattable> {
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) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight)
+ const videoCreated = await video.save(sequelizeOptions) as (MVideoAccountDefault & MVideoWithBlacklistLight & MVideoTag)
videoCreated.VideoChannel = videoChannel
if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
const tagInstances = await TagModel.findOrCreateTags(tags, t)
await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
+ videoCreated.Tags = tagInstances
+ } else {
+ videoCreated.Tags = []
}
// Create video import object in database
const videoImport = await VideoImportModel.create(
Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
sequelizeOptions
- ) as MVideoImportVideo
+ ) as MVideoImportFormattable
videoImport.Video = videoCreated
return videoImport