import { JobQueue } from '../../../lib/job-queue/job-queue'
import { join } from 'path'
import { isArray } from '../../../helpers/custom-validators/misc'
-import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
-import { VideoChannelModel } from '../../../models/video/video-channel'
import * as Bluebird from 'bluebird'
import * as parseTorrent from 'parse-torrent'
import { getSecureTorrentName } from '../../../helpers/utils'
import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
-import { createVideoThumbnailFromExisting } from '../../../lib/thumbnail'
+import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
-import { ThumbnailModel } from '../../../models/video/thumbnail'
+import {
+ MChannelAccountDefault,
+ MThumbnail,
+ MUser,
+ MVideoTag,
+ MVideoThumbnailAccountDefault,
+ MVideoWithBlacklistLight
+} from '@server/typings/models'
+import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router()
previewModel,
videoChannel: res.locals.videoChannel,
tags,
- videoImportAttributes
+ videoImportAttributes,
+ user
})
// Create job to import the video
userId: user.id
}
const videoImport = await insertIntoDB({
- video: video,
+ video,
thumbnailModel,
previewModel,
videoChannel: res.locals.videoChannel,
tags,
- videoImportAttributes
+ videoImportAttributes,
+ user
})
// Create job to import the video
if (thumbnailField) {
const thumbnailPhysicalFile = thumbnailField[ 0 ]
- return createVideoThumbnailFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.THUMBNAIL)
+ return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE, false)
}
return undefined
if (previewField) {
const previewPhysicalFile = previewField[0]
- return createVideoThumbnailFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW)
+ return createVideoMiniatureFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW, false)
}
return undefined
}
function insertIntoDB (parameters: {
- video: VideoModel,
- thumbnailModel: ThumbnailModel,
- previewModel: ThumbnailModel,
- videoChannel: VideoChannelModel,
+ video: MVideoThumbnailAccountDefault,
+ thumbnailModel: MThumbnail,
+ previewModel: MThumbnail,
+ videoChannel: MChannelAccountDefault,
tags: string[],
- videoImportAttributes: FilteredModelAttributes<VideoImportModel>
-}): Bluebird<VideoImportModel> {
- let { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes } = parameters
+ videoImportAttributes: Partial<MVideoImport>,
+ user: MUser
+}): Bluebird<MVideoImportVideo> {
+ 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)
+ const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag)
videoCreated.VideoChannel = videoChannel
- if (thumbnailModel) {
- thumbnailModel.videoId = videoCreated.id
- videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t }))
- }
- if (previewModel) {
- previewModel.videoId = videoCreated.id
- videoCreated.addThumbnail(await previewModel.save({ transaction: t }))
- }
+ if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
+ if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
- await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t)
+ await autoBlacklistVideoIfNeeded({
+ video: videoCreated,
+ user,
+ notify: false,
+ isRemote: false,
+ isNew: true,
+ transaction: t
+ })
// Set tags to the video
if (tags) {
const videoImport = await VideoImportModel.create(
Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
sequelizeOptions
- )
+ ) as MVideoImportVideo
videoImport.Video = videoCreated
return videoImport