-import * as express from 'express'
-import { v4 as uuidv4 } from 'uuid'
+import express from 'express'
import { createReqFiles } from '@server/helpers/express-utils'
import { CONFIG } from '@server/initializers/config'
import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants'
import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live'
import { VideoLiveModel } from '@server/models/video/video-live'
import { MVideoDetails, MVideoFullLight } from '@server/types/models'
-import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared'
+import { buildUUID, uuidToShort } from '@shared/extra-utils'
+import { HttpStatusCode, LiveVideoCreate, LiveVideoUpdate, VideoState } from '@shared/models'
import { logger } from '../../../helpers/logger'
import { sequelizeTypescript } from '../../../initializers/database'
import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
import { VideoModel } from '../../../models/video/video'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
const liveRouter = express.Router()
liveRouter.get('/live/:videoId',
authenticate,
asyncMiddleware(videoLiveGetValidator),
- asyncRetryTransactionMiddleware(getLiveVideo)
+ getLiveVideo
)
liveRouter.put('/live/:videoId',
// ---------------------------------------------------------------------------
-async function getLiveVideo (req: express.Request, res: express.Response) {
+function getLiveVideo (req: express.Request, res: express.Response) {
const videoLive = res.locals.videoLive
return res.json(videoLive.toFormattedJSON())
const videoInfo: LiveVideoCreate = req.body
// Prepare data so we don't block the transaction
- const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id)
+ let videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id)
+ videoData = await Hooks.wrapObject(videoData, 'filter:api.video.live.video-attribute.result')
+
videoData.isLive = true
videoData.state = VideoState.WAITING_FOR_LIVE
videoData.duration = 0
const videoLive = new VideoLiveModel()
videoLive.saveReplay = videoInfo.saveReplay || false
videoLive.permanentLive = videoInfo.permanentLive || false
- videoLive.streamKey = uuidv4()
+ videoLive.streamKey = buildUUID()
const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({
video,
return { videoCreated }
})
- Hooks.runAction('action:api.live-video.created', { video: videoCreated })
+ Hooks.runAction('action:api.live-video.created', { video: videoCreated, req, res })
return res.json({
video: {
id: videoCreated.id,
+ shortUUID: uuidToShort(videoCreated.uuid),
uuid: videoCreated.uuid
}
})