aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/import.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/import.ts')
-rw-r--r--server/controllers/api/videos/import.ts34
1 files changed, 18 insertions, 16 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 04c9b547b..adc2f9aa2 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -15,7 +15,6 @@ import { VideoImportModel } from '../../../models/video/video-import'
15import { JobQueue } from '../../../lib/job-queue/job-queue' 15import { JobQueue } from '../../../lib/job-queue/job-queue'
16import { join } from 'path' 16import { join } from 'path'
17import { isArray } from '../../../helpers/custom-validators/misc' 17import { isArray } from '../../../helpers/custom-validators/misc'
18import { VideoChannelModel } from '../../../models/video/video-channel'
19import * as Bluebird from 'bluebird' 18import * as Bluebird from 'bluebird'
20import * as parseTorrent from 'parse-torrent' 19import * as parseTorrent from 'parse-torrent'
21import { getSecureTorrentName } from '../../../helpers/utils' 20import { getSecureTorrentName } from '../../../helpers/utils'
@@ -25,8 +24,14 @@ import { CONFIG } from '../../../initializers/config'
25import { sequelizeTypescript } from '../../../initializers/database' 24import { sequelizeTypescript } from '../../../initializers/database'
26import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 25import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 26import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
28import { ThumbnailModel } from '../../../models/video/thumbnail' 27import {
29import { UserModel } from '../../../models/account/user' 28 MChannelActorAccountDefault,
29 MThumbnail,
30 MUser,
31 MVideoThumbnailAccountDefault,
32 MVideoWithBlacklistLight
33} from '@server/typings/models'
34import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
30 35
31const auditLogger = auditLoggerFactory('video-imports') 36const auditLogger = auditLoggerFactory('video-imports')
32const videoImportsRouter = express.Router() 37const videoImportsRouter = express.Router()
@@ -225,28 +230,28 @@ async function processPreview (req: express.Request, video: VideoModel) {
225} 230}
226 231
227function insertIntoDB (parameters: { 232function insertIntoDB (parameters: {
228 video: VideoModel, 233 video: MVideoThumbnailAccountDefault,
229 thumbnailModel: ThumbnailModel, 234 thumbnailModel: MThumbnail,
230 previewModel: ThumbnailModel, 235 previewModel: MThumbnail,
231 videoChannel: VideoChannelModel, 236 videoChannel: MChannelActorAccountDefault,
232 tags: string[], 237 tags: string[],
233 videoImportAttributes: Partial<VideoImportModel>, 238 videoImportAttributes: Partial<MVideoImport>,
234 user: UserModel 239 user: MUser
235}): Bluebird<VideoImportModel> { 240}): Bluebird<MVideoImportVideo> {
236 const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters 241 const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
237 242
238 return sequelizeTypescript.transaction(async t => { 243 return sequelizeTypescript.transaction(async t => {
239 const sequelizeOptions = { transaction: t } 244 const sequelizeOptions = { transaction: t }
240 245
241 // Save video object in database 246 // Save video object in database
242 const videoCreated = await video.save(sequelizeOptions) 247 const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight)
243 videoCreated.VideoChannel = videoChannel 248 videoCreated.VideoChannel = videoChannel
244 249
245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 250 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) 251 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
247 252
248 await autoBlacklistVideoIfNeeded({ 253 await autoBlacklistVideoIfNeeded({
249 video, 254 video: videoCreated,
250 user, 255 user,
251 notify: false, 256 notify: false,
252 isRemote: false, 257 isRemote: false,
@@ -259,16 +264,13 @@ function insertIntoDB (parameters: {
259 const tagInstances = await TagModel.findOrCreateTags(tags, t) 264 const tagInstances = await TagModel.findOrCreateTags(tags, t)
260 265
261 await videoCreated.$set('Tags', tagInstances, sequelizeOptions) 266 await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
262 videoCreated.Tags = tagInstances
263 } else {
264 videoCreated.Tags = []
265 } 267 }
266 268
267 // Create video import object in database 269 // Create video import object in database
268 const videoImport = await VideoImportModel.create( 270 const videoImport = await VideoImportModel.create(
269 Object.assign({ videoId: videoCreated.id }, videoImportAttributes), 271 Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
270 sequelizeOptions 272 sequelizeOptions
271 ) 273 ) as MVideoImportVideo
272 videoImport.Video = videoCreated 274 videoImport.Video = videoCreated
273 275
274 return videoImport 276 return videoImport