aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/live.ts')
-rw-r--r--server/controllers/api/videos/live.ts40
1 files changed, 15 insertions, 25 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index d08ef9869..97b135f96 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -4,18 +4,16 @@ import { createReqFiles } from '@server/helpers/express-utils'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' 5import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants'
6import { getVideoActivityPubUrl } from '@server/lib/activitypub/url' 6import { getVideoActivityPubUrl } from '@server/lib/activitypub/url'
7import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
7import { videoLiveAddValidator, videoLiveGetValidator } from '@server/middlewares/validators/videos/video-live' 8import { videoLiveAddValidator, videoLiveGetValidator } from '@server/middlewares/validators/videos/video-live'
8import { VideoLiveModel } from '@server/models/video/video-live' 9import { VideoLiveModel } from '@server/models/video/video-live'
9import { MVideoDetails, MVideoFullLight } from '@server/types/models' 10import { MVideoDetails, MVideoFullLight } from '@server/types/models'
10import { VideoCreate, VideoPrivacy, VideoState } from '../../../../shared' 11import { VideoCreate, VideoState } from '../../../../shared'
11import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
12import { logger } from '../../../helpers/logger' 12import { logger } from '../../../helpers/logger'
13import { sequelizeTypescript } from '../../../initializers/database' 13import { sequelizeTypescript } from '../../../initializers/database'
14import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 14import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
15import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 15import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
16import { TagModel } from '../../../models/video/tag'
17import { VideoModel } from '../../../models/video/video' 16import { VideoModel } from '../../../models/video/video'
18import { buildLocalVideoFromCreate } from '@server/lib/video'
19 17
20const liveRouter = express.Router() 18const liveRouter = express.Router()
21 19
@@ -59,26 +57,24 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
59 const videoInfo: VideoCreate = req.body 57 const videoInfo: VideoCreate = req.body
60 58
61 // Prepare data so we don't block the transaction 59 // Prepare data so we don't block the transaction
62 const videoData = buildLocalVideoFromCreate(videoInfo, res.locals.videoChannel.id) 60 const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id)
63 videoData.isLive = true 61 videoData.isLive = true
64 62 videoData.state = VideoState.WAITING_FOR_LIVE
65 const videoLive = new VideoLiveModel() 63 videoData.duration = 0
66 videoLive.streamKey = uuidv4()
67 64
68 const video = new VideoModel(videoData) as MVideoDetails 65 const video = new VideoModel(videoData) as MVideoDetails
69 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object 66 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
70 67
71 // Process thumbnail or create it from the video 68 const videoLive = new VideoLiveModel()
72 const thumbnailField = req.files ? req.files['thumbnailfile'] : null 69 videoLive.streamKey = uuidv4()
73 const thumbnailModel = thumbnailField
74 ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE, false)
75 : await createVideoMiniatureFromExisting(ASSETS_PATH.DEFAULT_LIVE_BACKGROUND, video, ThumbnailType.MINIATURE, true)
76 70
77 // Process preview or create it from the video 71 const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({
78 const previewField = req.files ? req.files['previewfile'] : null 72 video,
79 const previewModel = previewField 73 files: req.files,
80 ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW, false) 74 fallback: type => {
81 : await createVideoMiniatureFromExisting(ASSETS_PATH.DEFAULT_LIVE_BACKGROUND, video, ThumbnailType.PREVIEW, true) 75 return createVideoMiniatureFromExisting({ inputPath: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND, video, type, automaticallyGenerated: true })
76 }
77 })
82 78
83 const { videoCreated } = await sequelizeTypescript.transaction(async t => { 79 const { videoCreated } = await sequelizeTypescript.transaction(async t => {
84 const sequelizeOptions = { transaction: t } 80 const sequelizeOptions = { transaction: t }
@@ -94,13 +90,7 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
94 videoLive.videoId = videoCreated.id 90 videoLive.videoId = videoCreated.id
95 await videoLive.save(sequelizeOptions) 91 await videoLive.save(sequelizeOptions)
96 92
97 // Create tags 93 await setVideoTags({ video, tags: videoInfo.tags, transaction: t })
98 if (videoInfo.tags !== undefined) {
99 const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t)
100
101 await video.$set('Tags', tagInstances, sequelizeOptions)
102 video.Tags = tagInstances
103 }
104 94
105 logger.info('Video live %s with uuid %s created.', videoInfo.name, videoCreated.uuid) 95 logger.info('Video live %s with uuid %s created.', videoInfo.name, videoCreated.uuid)
106 96