1 import { Transaction } from 'sequelize/types'
2 import { TagModel } from '@server/models/video/tag'
3 import { VideoModel } from '@server/models/video/video'
4 import { FilteredModelAttributes } from '@server/types'
5 import { MTag, MThumbnail, MVideoTag, MVideoThumbnail } from '@server/types/models'
6 import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models'
7 import { createVideoMiniatureFromExisting } from './thumbnail'
9 function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
13 category: videoInfo.category,
14 licence: videoInfo.licence,
15 language: videoInfo.language,
16 commentsEnabled: videoInfo.commentsEnabled !== false, // If the value is not "false", the default is "true"
17 downloadEnabled: videoInfo.downloadEnabled !== false,
18 waitTranscoding: videoInfo.waitTranscoding || false,
19 nsfw: videoInfo.nsfw || false,
20 description: videoInfo.description,
21 support: videoInfo.support,
22 privacy: videoInfo.privacy || VideoPrivacy.PRIVATE,
24 originallyPublishedAt: videoInfo.originallyPublishedAt
28 async function buildVideoThumbnailsFromReq (options: {
29 video: MVideoThumbnail
30 files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[]
31 fallback: (type: ThumbnailType) => Promise<MThumbnail>
32 automaticallyGenerated?: boolean
34 const { video, files, fallback, automaticallyGenerated } = options
38 type: ThumbnailType.MINIATURE,
39 fieldName: 'thumbnailfile'
42 type: ThumbnailType.PREVIEW,
43 fieldName: 'previewfile'
46 const fields = files?.[p.fieldName]
49 return createVideoMiniatureFromExisting({
50 inputPath: fields[0].path,
53 automaticallyGenerated: automaticallyGenerated || false
57 return fallback(p.type)
60 return Promise.all(promises)
63 async function setVideoTags (options: {
66 transaction?: Transaction
69 const { video, tags, transaction, defaultValue } = options
70 // Set tags to the video
72 const tagInstances = await TagModel.findOrCreateTags(tags, transaction)
74 await video.$set('Tags', tagInstances, { transaction })
75 video.Tags = tagInstances
77 video.Tags = defaultValue || []
81 // ---------------------------------------------------------------------------
84 buildLocalVideoFromReq,
85 buildVideoThumbnailsFromReq,