aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/controllers/api/videos/blacklist.ts
blob: d8f2068ec547c4469f31561f0e3bfd20ebd1a8a0 (plain) (tree)
1
2
3
                                  
 
                                                               












                                         




                                                                              


                 


                                                                              
                                                                                                        





                                        


                                                   
                                                          
                      
      
 
import * as express from 'express'

import { database as db } from '../../../initializers/database'
import { logger } from '../../../helpers'
import {
  authenticate,
  ensureIsAdmin,
  videosBlacklistValidator
} from '../../../middlewares'

const blacklistRouter = express.Router()

blacklistRouter.post('/:id/blacklist',
  authenticate,
  ensureIsAdmin,
  videosBlacklistValidator,
  addVideoToBlacklist
)

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

export {
  blacklistRouter
}

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

function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
  const videoInstance = res.locals.video

  const toCreate = {
    videoId: videoInstance.id
  }

  db.BlacklistedVideo.create(toCreate)
    .then(() => res.type('json').status(204).end())
    .catch(err => {
      logger.error('Errors when blacklisting video ', err)
      return next(err)
    })
}