aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r--server/lib/video.ts68
1 files changed, 62 insertions, 6 deletions
diff --git a/server/lib/video.ts b/server/lib/video.ts
index a28f31529..6df41e6cd 100644
--- a/server/lib/video.ts
+++ b/server/lib/video.ts
@@ -1,9 +1,12 @@
1 1import { Transaction } from 'sequelize/types'
2import { TagModel } from '@server/models/video/tag'
2import { VideoModel } from '@server/models/video/video' 3import { VideoModel } from '@server/models/video/video'
3import { FilteredModelAttributes } from '@server/types' 4import { FilteredModelAttributes } from '@server/types'
4import { VideoCreate, VideoPrivacy, VideoState } from '@shared/models' 5import { MTag, MThumbnail, MVideoTag, MVideoThumbnail } from '@server/types/models'
6import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models'
7import { createVideoMiniatureFromExisting } from './thumbnail'
5 8
6function buildLocalVideoFromCreate (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { 9function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
7 return { 10 return {
8 name: videoInfo.name, 11 name: videoInfo.name,
9 remote: false, 12 remote: false,
@@ -13,19 +16,72 @@ function buildLocalVideoFromCreate (videoInfo: VideoCreate, channelId: number):
13 commentsEnabled: videoInfo.commentsEnabled !== false, // If the value is not "false", the default is "true" 16 commentsEnabled: videoInfo.commentsEnabled !== false, // If the value is not "false", the default is "true"
14 downloadEnabled: videoInfo.downloadEnabled !== false, 17 downloadEnabled: videoInfo.downloadEnabled !== false,
15 waitTranscoding: videoInfo.waitTranscoding || false, 18 waitTranscoding: videoInfo.waitTranscoding || false,
16 state: VideoState.WAITING_FOR_LIVE,
17 nsfw: videoInfo.nsfw || false, 19 nsfw: videoInfo.nsfw || false,
18 description: videoInfo.description, 20 description: videoInfo.description,
19 support: videoInfo.support, 21 support: videoInfo.support,
20 privacy: videoInfo.privacy || VideoPrivacy.PRIVATE, 22 privacy: videoInfo.privacy || VideoPrivacy.PRIVATE,
21 duration: 0,
22 channelId: channelId, 23 channelId: channelId,
23 originallyPublishedAt: videoInfo.originallyPublishedAt 24 originallyPublishedAt: videoInfo.originallyPublishedAt
24 } 25 }
25} 26}
26 27
28async 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
33}) {
34 const { video, files, fallback, automaticallyGenerated } = options
35
36 const promises = [
37 {
38 type: ThumbnailType.MINIATURE,
39 fieldName: 'thumbnailfile'
40 },
41 {
42 type: ThumbnailType.PREVIEW,
43 fieldName: 'previewfile'
44 }
45 ].map(p => {
46 const fields = files?.[p.fieldName]
47
48 if (fields) {
49 return createVideoMiniatureFromExisting({
50 inputPath: fields[0].path,
51 video,
52 type: p.type,
53 automaticallyGenerated: automaticallyGenerated || false
54 })
55 }
56
57 return fallback(p.type)
58 })
59
60 return Promise.all(promises)
61}
62
63async function setVideoTags (options: {
64 video: MVideoTag
65 tags: string[]
66 transaction?: Transaction
67 defaultValue?: MTag[]
68}) {
69 const { video, tags, transaction, defaultValue } = options
70 // Set tags to the video
71 if (tags) {
72 const tagInstances = await TagModel.findOrCreateTags(tags, transaction)
73
74 await video.$set('Tags', tagInstances, { transaction })
75 video.Tags = tagInstances
76 } else {
77 video.Tags = defaultValue || []
78 }
79}
80
27// --------------------------------------------------------------------------- 81// ---------------------------------------------------------------------------
28 82
29export { 83export {
30 buildLocalVideoFromCreate 84 buildLocalVideoFromReq,
85 buildVideoThumbnailsFromReq,
86 setVideoTags
31} 87}