]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/import.ts
Add ability to disable webtorrent
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / import.ts
index adc2f9aa2a625b6a9d1ee84338c244e39bcb0efd..28ced58368b2939f0957d09cb0f69f0723793646 100644 (file)
@@ -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<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)
@@ -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