diff options
author | Chocobozzz <me@florianbigard.com> | 2020-10-26 16:44:23 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | b5b687550d8ef8beafdf706e45d6556fb5f4c876 (patch) | |
tree | 232412d463c78af1f7ab5797db5aecf1096d08da /server/controllers | |
parent | ef680f68351ec10ab73a1131570a6d14ce14c195 (diff) | |
download | PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.gz PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.zst PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.zip |
Add ability to save live replay
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/live.ts | 37 |
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' | |||
5 | import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' | 5 | import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' |
6 | import { getVideoActivityPubUrl } from '@server/lib/activitypub/url' | 6 | import { getVideoActivityPubUrl } from '@server/lib/activitypub/url' |
7 | import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 7 | import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
8 | import { videoLiveAddValidator, videoLiveGetValidator } from '@server/middlewares/validators/videos/video-live' | 8 | import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live' |
9 | import { VideoLiveModel } from '@server/models/video/video-live' | 9 | import { VideoLiveModel } from '@server/models/video/video-live' |
10 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' | 10 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' |
11 | import { VideoCreate, VideoState } from '../../../../shared' | 11 | import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared' |
12 | import { logger } from '../../../helpers/logger' | 12 | import { logger } from '../../../helpers/logger' |
13 | import { sequelizeTypescript } from '../../../initializers/database' | 13 | import { sequelizeTypescript } from '../../../initializers/database' |
14 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' | 14 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
@@ -36,7 +36,14 @@ liveRouter.post('/live', | |||
36 | liveRouter.get('/live/:videoId', | 36 | liveRouter.get('/live/:videoId', |
37 | authenticate, | 37 | authenticate, |
38 | asyncMiddleware(videoLiveGetValidator), | 38 | asyncMiddleware(videoLiveGetValidator), |
39 | asyncRetryTransactionMiddleware(getVideoLive) | 39 | asyncRetryTransactionMiddleware(getLiveVideo) |
40 | ) | ||
41 | |||
42 | liveRouter.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 | ||
50 | async function getVideoLive (req: express.Request, res: express.Response) { | 57 | async 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 | ||
63 | async 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 | |||
56 | async function addLiveVideo (req: express.Request, res: express.Response) { | 74 | async 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 | ||