diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/videos/live.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index e51658927..ec4c073b5 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts | |||
@@ -1,13 +1,21 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { exists } from '@server/helpers/custom-validators/misc' | 2 | import { exists } from '@server/helpers/custom-validators/misc' |
3 | import { createReqFiles } from '@server/helpers/express-utils' | 3 | import { createReqFiles } from '@server/helpers/express-utils' |
4 | import { getFormattedObjects } from '@server/helpers/utils' | ||
4 | import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' | 5 | import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' |
5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 6 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 7 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
7 | import { Hooks } from '@server/lib/plugins/hooks' | 8 | import { Hooks } from '@server/lib/plugins/hooks' |
8 | import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 9 | import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
9 | import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live' | 10 | import { |
11 | videoLiveAddValidator, | ||
12 | videoLiveFindReplaySessionValidator, | ||
13 | videoLiveGetValidator, | ||
14 | videoLiveListSessionsValidator, | ||
15 | videoLiveUpdateValidator | ||
16 | } from '@server/middlewares/validators/videos/video-live' | ||
10 | import { VideoLiveModel } from '@server/models/video/video-live' | 17 | import { VideoLiveModel } from '@server/models/video/video-live' |
18 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' | ||
11 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' | 19 | import { MVideoDetails, MVideoFullLight } from '@server/types/models' |
12 | import { buildUUID, uuidToShort } from '@shared/extra-utils' | 20 | import { buildUUID, uuidToShort } from '@shared/extra-utils' |
13 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' | 21 | import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' |
@@ -28,6 +36,13 @@ liveRouter.post('/live', | |||
28 | asyncRetryTransactionMiddleware(addLiveVideo) | 36 | asyncRetryTransactionMiddleware(addLiveVideo) |
29 | ) | 37 | ) |
30 | 38 | ||
39 | liveRouter.get('/live/:videoId/sessions', | ||
40 | authenticate, | ||
41 | asyncMiddleware(videoLiveGetValidator), | ||
42 | videoLiveListSessionsValidator, | ||
43 | asyncMiddleware(getLiveVideoSessions) | ||
44 | ) | ||
45 | |||
31 | liveRouter.get('/live/:videoId', | 46 | liveRouter.get('/live/:videoId', |
32 | optionalAuthenticate, | 47 | optionalAuthenticate, |
33 | asyncMiddleware(videoLiveGetValidator), | 48 | asyncMiddleware(videoLiveGetValidator), |
@@ -41,6 +56,11 @@ liveRouter.put('/live/:videoId', | |||
41 | asyncRetryTransactionMiddleware(updateLiveVideo) | 56 | asyncRetryTransactionMiddleware(updateLiveVideo) |
42 | ) | 57 | ) |
43 | 58 | ||
59 | liveRouter.get('/:videoId/live-session', | ||
60 | asyncMiddleware(videoLiveFindReplaySessionValidator), | ||
61 | getLiveReplaySession | ||
62 | ) | ||
63 | |||
44 | // --------------------------------------------------------------------------- | 64 | // --------------------------------------------------------------------------- |
45 | 65 | ||
46 | export { | 66 | export { |
@@ -55,6 +75,20 @@ function getLiveVideo (req: express.Request, res: express.Response) { | |||
55 | return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res))) | 75 | return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res))) |
56 | } | 76 | } |
57 | 77 | ||
78 | function getLiveReplaySession (req: express.Request, res: express.Response) { | ||
79 | const session = res.locals.videoLiveSession | ||
80 | |||
81 | return res.json(session.toFormattedJSON()) | ||
82 | } | ||
83 | |||
84 | async function getLiveVideoSessions (req: express.Request, res: express.Response) { | ||
85 | const videoLive = res.locals.videoLive | ||
86 | |||
87 | const data = await VideoLiveSessionModel.listSessionsOfLiveForAPI({ videoId: videoLive.videoId }) | ||
88 | |||
89 | return res.json(getFormattedObjects(data, data.length)) | ||
90 | } | ||
91 | |||
58 | function canSeePrivateLiveInformation (res: express.Response) { | 92 | function canSeePrivateLiveInformation (res: express.Response) { |
59 | const user = res.locals.oauth?.token.User | 93 | const user = res.locals.oauth?.token.User |
60 | if (!user) return false | 94 | if (!user) return false |