aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-10-26 16:44:23 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commitb5b687550d8ef8beafdf706e45d6556fb5f4c876 (patch)
tree232412d463c78af1f7ab5797db5aecf1096d08da /server/controllers/api/videos
parentef680f68351ec10ab73a1131570a6d14ce14c195 (diff)
downloadPeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.gz
PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.zst
PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.zip
Add ability to save live replay
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/live.ts37
1 files changed, 31 insertions, 6 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index 97b135f96..be46fb1c6 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -5,10 +5,10 @@ import { 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 { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
8import { videoLiveAddValidator, videoLiveGetValidator } from '@server/middlewares/validators/videos/video-live' 8import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live'
9import { VideoLiveModel } from '@server/models/video/video-live' 9import { VideoLiveModel } from '@server/models/video/video-live'
10import { MVideoDetails, MVideoFullLight } from '@server/types/models' 10import { MVideoDetails, MVideoFullLight } from '@server/types/models'
11import { VideoCreate, VideoState } from '../../../../shared' 11import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared'
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'
@@ -36,7 +36,14 @@ liveRouter.post('/live',
36liveRouter.get('/live/:videoId', 36liveRouter.get('/live/:videoId',
37 authenticate, 37 authenticate,
38 asyncMiddleware(videoLiveGetValidator), 38 asyncMiddleware(videoLiveGetValidator),
39 asyncRetryTransactionMiddleware(getVideoLive) 39 asyncRetryTransactionMiddleware(getLiveVideo)
40)
41
42liveRouter.put('/live/:videoId',
43 authenticate,
44 asyncMiddleware(videoLiveGetValidator),
45 videoLiveUpdateValidator,
46 asyncRetryTransactionMiddleware(updateLiveVideo)
40) 47)
41 48
42// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
@@ -47,14 +54,25 @@ export {
47 54
48// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
49 56
50async function getVideoLive (req: express.Request, res: express.Response) { 57async function getLiveVideo (req: express.Request, res: express.Response) {
51 const videoLive = res.locals.videoLive 58 const videoLive = res.locals.videoLive
52 59
53 return res.json(videoLive.toFormattedJSON()) 60 return res.json(videoLive.toFormattedJSON())
54} 61}
55 62
63async function updateLiveVideo (req: express.Request, res: express.Response) {
64 const body: LiveVideoUpdate = req.body
65
66 const videoLive = res.locals.videoLive
67 videoLive.saveReplay = body.saveReplay || false
68
69 await videoLive.save()
70
71 return res.sendStatus(204)
72}
73
56async function addLiveVideo (req: express.Request, res: express.Response) { 74async function addLiveVideo (req: express.Request, res: express.Response) {
57 const videoInfo: VideoCreate = req.body 75 const videoInfo: LiveVideoCreate = req.body
58 76
59 // Prepare data so we don't block the transaction 77 // Prepare data so we don't block the transaction
60 const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) 78 const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id)
@@ -66,13 +84,20 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
66 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object 84 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
67 85
68 const videoLive = new VideoLiveModel() 86 const videoLive = new VideoLiveModel()
87 videoLive.saveReplay = videoInfo.saveReplay || false
69 videoLive.streamKey = uuidv4() 88 videoLive.streamKey = uuidv4()
70 89
71 const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({ 90 const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({
72 video, 91 video,
73 files: req.files, 92 files: req.files,
74 fallback: type => { 93 fallback: type => {
75 return createVideoMiniatureFromExisting({ inputPath: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND, video, type, automaticallyGenerated: true }) 94 return createVideoMiniatureFromExisting({
95 inputPath: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND,
96 video,
97 type,
98 automaticallyGenerated: true,
99 keepOriginal: true
100 })
76 } 101 }
77 }) 102 })
78 103