From 26e3e98ff0e222a9fb9226938ac6902af77921bd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 3 May 2022 11:38:07 +0200 Subject: Support live session in server --- server/controllers/api/videos/live.ts | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/videos') 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 @@ import express from 'express' import { exists } from '@server/helpers/custom-validators/misc' import { createReqFiles } from '@server/helpers/express-utils' +import { getFormattedObjects } from '@server/helpers/utils' import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' import { Hooks } from '@server/lib/plugins/hooks' import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' -import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live' +import { + videoLiveAddValidator, + videoLiveFindReplaySessionValidator, + videoLiveGetValidator, + videoLiveListSessionsValidator, + videoLiveUpdateValidator +} from '@server/middlewares/validators/videos/video-live' import { VideoLiveModel } from '@server/models/video/video-live' +import { VideoLiveSessionModel } from '@server/models/video/video-live-session' import { MVideoDetails, MVideoFullLight } from '@server/types/models' import { buildUUID, uuidToShort } from '@shared/extra-utils' import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' @@ -28,6 +36,13 @@ liveRouter.post('/live', asyncRetryTransactionMiddleware(addLiveVideo) ) +liveRouter.get('/live/:videoId/sessions', + authenticate, + asyncMiddleware(videoLiveGetValidator), + videoLiveListSessionsValidator, + asyncMiddleware(getLiveVideoSessions) +) + liveRouter.get('/live/:videoId', optionalAuthenticate, asyncMiddleware(videoLiveGetValidator), @@ -41,6 +56,11 @@ liveRouter.put('/live/:videoId', asyncRetryTransactionMiddleware(updateLiveVideo) ) +liveRouter.get('/:videoId/live-session', + asyncMiddleware(videoLiveFindReplaySessionValidator), + getLiveReplaySession +) + // --------------------------------------------------------------------------- export { @@ -55,6 +75,20 @@ function getLiveVideo (req: express.Request, res: express.Response) { return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res))) } +function getLiveReplaySession (req: express.Request, res: express.Response) { + const session = res.locals.videoLiveSession + + return res.json(session.toFormattedJSON()) +} + +async function getLiveVideoSessions (req: express.Request, res: express.Response) { + const videoLive = res.locals.videoLive + + const data = await VideoLiveSessionModel.listSessionsOfLiveForAPI({ videoId: videoLive.videoId }) + + return res.json(getFormattedObjects(data, data.length)) +} + function canSeePrivateLiveInformation (res: express.Response) { const user = res.locals.oauth?.token.User if (!user) return false -- cgit v1.2.3