aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/validators/videos/video-shares.ts
blob: c234de6ed53dfff68b1b3e69af101a19c6cc9d63 (plain) (tree)
1
2
3
4
5
6
7
8
                             
                                         
                                                                                
                                                                   
                                                                   
                                                                                    

                              


                            
                       

                                                                                      
                                             
                                                         
 
                                     


                                                                          
                                                     












                                                                              
import express from 'express'
import { param } from 'express-validator'
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
import { isIdValid } from '../../../helpers/custom-validators/misc'
import { VideoShareModel } from '../../../models/video/video-share'
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'

const videosShareValidator = [
  isValidVideoIdParam('id'),

  param('actorId')
    .custom(isIdValid),

  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
    if (areValidationErrors(req, res)) return
    if (!await doesVideoExist(req.params.id, res)) return

    const video = res.locals.videoAll

    const share = await VideoShareModel.load(req.params.actorId, video.id)
    if (!share) {
      return res.status(HttpStatusCode.NOT_FOUND_404)
                .end()
    }

    res.locals.videoShare = share
    return next()
  }
]

// ---------------------------------------------------------------------------

export {
  videosShareValidator
}