]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/videos/video-live.ts
store uploaded video filename (#4885)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-live.ts
index ff492da0fa93baa0d2de5b36e73abb2044fdea0e..59638d5e094fb3c743d96ed2e84da5c58295e50a 100644 (file)
@@ -28,6 +28,7 @@ import {
   isValidVideoIdParam
 } from '../shared'
 import { getCommonVideoEditAttributes } from './videos'
+import { VideoLiveSessionModel } from '@server/models/video/video-live-session'
 
 const videoLiveGetValidator = [
   isValidVideoIdParam('videoId'),
@@ -196,11 +197,48 @@ const videoLiveUpdateValidator = [
   }
 ]
 
+const videoLiveListSessionsValidator = [
+  (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking videoLiveListSessionsValidator parameters', { parameters: req.params })
+
+    // Check the user can manage the live
+    const user = res.locals.oauth.token.User
+    if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res)) return
+
+    return next()
+  }
+]
+
+const videoLiveFindReplaySessionValidator = [
+  isValidVideoIdParam('videoId'),
+
+  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking videoLiveFindReplaySessionValidator parameters', { parameters: req.params })
+
+    if (areValidationErrors(req, res)) return
+    if (!await doesVideoExist(req.params.videoId, res, 'id')) return
+
+    const session = await VideoLiveSessionModel.findSessionOfReplay(res.locals.videoId.id)
+    if (!session) {
+      return res.fail({
+        status: HttpStatusCode.NOT_FOUND_404,
+        message: 'No live replay found'
+      })
+    }
+
+    res.locals.videoLiveSession = session
+
+    return next()
+  }
+]
+
 // ---------------------------------------------------------------------------
 
 export {
   videoLiveAddValidator,
   videoLiveUpdateValidator,
+  videoLiveListSessionsValidator,
+  videoLiveFindReplaySessionValidator,
   videoLiveGetValidator
 }