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.ts72
1 files changed, 37 insertions, 35 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 24a237304..5840cd063 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -1,30 +1,10 @@
1import * as Bluebird from 'bluebird'
1import * as express from 'express' 2import * as express from 'express'
3import { move, readFile } from 'fs-extra'
2import * as magnetUtil from 'magnet-uri' 4import * as magnetUtil from 'magnet-uri'
3import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
4import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
5import { MIMETYPES } from '../../../initializers/constants'
6import { getYoutubeDLInfo, YoutubeDLInfo, getYoutubeDLSubs } from '../../../helpers/youtube-dl'
7import { createReqFiles } from '../../../helpers/express-utils'
8import { logger } from '../../../helpers/logger'
9import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
10import { VideoModel } from '../../../models/video/video'
11import { VideoCaptionModel } from '../../../models/video/video-caption'
12import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
13import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
14import { TagModel } from '../../../models/video/tag'
15import { VideoImportModel } from '../../../models/video/video-import'
16import { JobQueue } from '../../../lib/job-queue/job-queue'
17import { join } from 'path'
18import { isArray } from '../../../helpers/custom-validators/misc'
19import * as Bluebird from 'bluebird'
20import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
21import { getSecureTorrentName } from '../../../helpers/utils' 6import { join } from 'path'
22import { move, readFile } from 'fs-extra' 7import { setVideoTags } from '@server/lib/video'
23import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
24import { CONFIG } from '../../../initializers/config'
25import { sequelizeTypescript } from '../../../initializers/database'
26import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail'
27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
28import { 8import {
29 MChannelAccountDefault, 9 MChannelAccountDefault,
30 MThumbnail, 10 MThumbnail,
@@ -36,6 +16,26 @@ import {
36 MVideoWithBlacklistLight 16 MVideoWithBlacklistLight
37} from '@server/types/models' 17} from '@server/types/models'
38import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' 18import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import'
19import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
20import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
21import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
22import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
23import { isArray } from '../../../helpers/custom-validators/misc'
24import { createReqFiles } from '../../../helpers/express-utils'
25import { logger } from '../../../helpers/logger'
26import { getSecureTorrentName } from '../../../helpers/utils'
27import { getYoutubeDLInfo, getYoutubeDLSubs, YoutubeDLInfo } from '../../../helpers/youtube-dl'
28import { CONFIG } from '../../../initializers/config'
29import { MIMETYPES } from '../../../initializers/constants'
30import { sequelizeTypescript } from '../../../initializers/database'
31import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
32import { JobQueue } from '../../../lib/job-queue/job-queue'
33import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail'
34import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
35import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
36import { VideoModel } from '../../../models/video/video'
37import { VideoCaptionModel } from '../../../models/video/video-caption'
38import { VideoImportModel } from '../../../models/video/video-import'
39 39
40const auditLogger = auditLoggerFactory('video-imports') 40const auditLogger = auditLoggerFactory('video-imports')
41const videoImportsRouter = express.Router() 41const videoImportsRouter = express.Router()
@@ -260,7 +260,12 @@ async function processThumbnail (req: express.Request, video: VideoModel) {
260 if (thumbnailField) { 260 if (thumbnailField) {
261 const thumbnailPhysicalFile = thumbnailField[0] 261 const thumbnailPhysicalFile = thumbnailField[0]
262 262
263 return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE, false) 263 return createVideoMiniatureFromExisting({
264 inputPath: thumbnailPhysicalFile.path,
265 video,
266 type: ThumbnailType.MINIATURE,
267 automaticallyGenerated: false
268 })
264 } 269 }
265 270
266 return undefined 271 return undefined
@@ -271,7 +276,12 @@ async function processPreview (req: express.Request, video: VideoModel) {
271 if (previewField) { 276 if (previewField) {
272 const previewPhysicalFile = previewField[0] 277 const previewPhysicalFile = previewField[0]
273 278
274 return createVideoMiniatureFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW, false) 279 return createVideoMiniatureFromExisting({
280 inputPath: previewPhysicalFile.path,
281 video,
282 type: ThumbnailType.PREVIEW,
283 automaticallyGenerated: false
284 })
275 } 285 }
276 286
277 return undefined 287 return undefined
@@ -325,15 +335,7 @@ function insertIntoDB (parameters: {
325 transaction: t 335 transaction: t
326 }) 336 })
327 337
328 // Set tags to the video 338 await setVideoTags({ video: videoCreated, tags, transaction: t })
329 if (tags) {
330 const tagInstances = await TagModel.findOrCreateTags(tags, t)
331
332 await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
333 videoCreated.Tags = tagInstances
334 } else {
335 videoCreated.Tags = []
336 }
337 339
338 // Create video import object in database 340 // Create video import object in database
339 const videoImport = await VideoImportModel.create( 341 const videoImport = await VideoImportModel.create(