]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/videos/blacklist.ts
fb4d57d7ba6077b200d32b52104298997b4d00e1
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / blacklist.ts
1 import express = require('express')
2
3 import { database as db } from '../../../initializers/database'
4 import { logger } from '../../../helpers'
5 import {
6 authenticate,
7 ensureIsAdmin,
8 videosBlacklistValidator
9 } from '../../../middlewares'
10
11 const blacklistRouter = express.Router()
12
13 blacklistRouter.post('/:id/blacklist',
14 authenticate,
15 ensureIsAdmin,
16 videosBlacklistValidator,
17 addVideoToBlacklist
18 )
19
20 // ---------------------------------------------------------------------------
21
22 export {
23 blacklistRouter
24 }
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 }