aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/blacklist.js
blob: 8c3e2a69d8d32d365660c354edeffdbeb49ff0f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict'

const express = require('express')

const db = require('../../../initializers/database')
const logger = require('../../../helpers/logger')
const middlewares = require('../../../middlewares')
const admin = middlewares.admin
const oAuth = middlewares.oauth
const validators = middlewares.validators
const validatorsVideos = validators.videos

const router = express.Router()

router.post('/:id/blacklist',
  oAuth.authenticate,
  admin.ensureIsAdmin,
  validatorsVideos.videosBlacklist,
  addVideoToBlacklist
)

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

module.exports = router

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

function addVideoToBlacklist (req, res, next) {
  const videoInstance = res.locals.video

  const toCreate = {
    videoId: videoInstance.id
  }

  db.BlacklistedVideo.create(toCreate).asCallback(function (err) {
    if (err) {
      logger.error('Errors when blacklisting video ', { error: err })
      return next(err)
    }

    return res.type('json').status(204).end()
  })
}