]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/videos/blacklist.js
Server: split videos controller
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / blacklist.js
1 'use strict'
2
3 const express = require('express')
4
5 const db = require('../../../initializers/database')
6 const logger = require('../../../helpers/logger')
7 const middlewares = require('../../../middlewares')
8 const admin = middlewares.admin
9 const oAuth = middlewares.oauth
10 const validators = middlewares.validators
11 const validatorsVideos = validators.videos
12
13 const router = express.Router()
14
15 router.post('/:id/blacklist',
16 oAuth.authenticate,
17 admin.ensureIsAdmin,
18 validatorsVideos.videosBlacklist,
19 addVideoToBlacklist
20 )
21
22 // ---------------------------------------------------------------------------
23
24 module.exports = router
25
26 // ---------------------------------------------------------------------------
27
28 function addVideoToBlacklist (req, res, next) {
29 const videoInstance = res.locals.video
30
31 const toCreate = {
32 videoId: videoInstance.id
33 }
34
35 db.BlacklistedVideo.create(toCreate).asCallback(function (err) {
36 if (err) {
37 logger.error('Errors when blacklisting video ', { error: err })
38 return next(err)
39 }
40
41 return res.type('json').status(204).end()
42 })
43 }