X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fimport.ts;h=28ced58368b2939f0957d09cb0f69f0723793646;hb=d7a25329f9e607894d29ab342b9cb66638b56dc0;hp=adc2f9aa2a625b6a9d1ee84338c244e39bcb0efd;hpb=453e83ea5d81d203ba34bc43cd5c2c750ba40568;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index adc2f9aa2..28ced5836 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -1,6 +1,5 @@ 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' @@ -25,13 +24,15 @@ import { sequelizeTypescript } from '../../../initializers/database' 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() @@ -189,8 +190,8 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You 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, @@ -233,18 +234,18 @@ function insertIntoDB (parameters: { video: MVideoThumbnailAccountDefault, thumbnailModel: MThumbnail, previewModel: MThumbnail, - videoChannel: MChannelActorAccountDefault, + videoChannel: MChannelAccountDefault, tags: string[], videoImportAttributes: Partial, user: MUser -}): Bluebird { +}): Bluebird { 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) @@ -264,13 +265,16 @@ function insertIntoDB (parameters: { 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