diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-17 10:00:46 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | 1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb (patch) | |
tree | 8bb02f8dc2590e5071306fb311bdc53289e20336 /server/controllers/api/videos/import.ts | |
parent | c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e (diff) | |
download | PeerTube-1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb.tar.gz PeerTube-1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb.tar.zst PeerTube-1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb.zip |
Refactor video creation
Diffstat (limited to 'server/controllers/api/videos/import.ts')
-rw-r--r-- | server/controllers/api/videos/import.ts | 72 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { move, readFile } from 'fs-extra' | ||
2 | import * as magnetUtil from 'magnet-uri' | 4 | import * as magnetUtil from 'magnet-uri' |
3 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | ||
4 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | ||
5 | import { MIMETYPES } from '../../../initializers/constants' | ||
6 | import { getYoutubeDLInfo, YoutubeDLInfo, getYoutubeDLSubs } from '../../../helpers/youtube-dl' | ||
7 | import { createReqFiles } from '../../../helpers/express-utils' | ||
8 | import { logger } from '../../../helpers/logger' | ||
9 | import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' | ||
10 | import { VideoModel } from '../../../models/video/video' | ||
11 | import { VideoCaptionModel } from '../../../models/video/video-caption' | ||
12 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | ||
13 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | ||
14 | import { TagModel } from '../../../models/video/tag' | ||
15 | import { VideoImportModel } from '../../../models/video/video-import' | ||
16 | import { JobQueue } from '../../../lib/job-queue/job-queue' | ||
17 | import { join } from 'path' | ||
18 | import { isArray } from '../../../helpers/custom-validators/misc' | ||
19 | import * as Bluebird from 'bluebird' | ||
20 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
21 | import { getSecureTorrentName } from '../../../helpers/utils' | 6 | import { join } from 'path' |
22 | import { move, readFile } from 'fs-extra' | 7 | import { setVideoTags } from '@server/lib/video' |
23 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | ||
24 | import { CONFIG } from '../../../initializers/config' | ||
25 | import { sequelizeTypescript } from '../../../initializers/database' | ||
26 | import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail' | ||
27 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | ||
28 | import { | 8 | import { |
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' |
38 | import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' | 18 | import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import' |
19 | import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' | ||
20 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | ||
21 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | ||
22 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | ||
23 | import { isArray } from '../../../helpers/custom-validators/misc' | ||
24 | import { createReqFiles } from '../../../helpers/express-utils' | ||
25 | import { logger } from '../../../helpers/logger' | ||
26 | import { getSecureTorrentName } from '../../../helpers/utils' | ||
27 | import { getYoutubeDLInfo, getYoutubeDLSubs, YoutubeDLInfo } from '../../../helpers/youtube-dl' | ||
28 | import { CONFIG } from '../../../initializers/config' | ||
29 | import { MIMETYPES } from '../../../initializers/constants' | ||
30 | import { sequelizeTypescript } from '../../../initializers/database' | ||
31 | import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' | ||
32 | import { JobQueue } from '../../../lib/job-queue/job-queue' | ||
33 | import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail' | ||
34 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | ||
35 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | ||
36 | import { VideoModel } from '../../../models/video/video' | ||
37 | import { VideoCaptionModel } from '../../../models/video/video-caption' | ||
38 | import { VideoImportModel } from '../../../models/video/video-import' | ||
39 | 39 | ||
40 | const auditLogger = auditLoggerFactory('video-imports') | 40 | const auditLogger = auditLoggerFactory('video-imports') |
41 | const videoImportsRouter = express.Router() | 41 | const 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( |