]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/blacklist.ts
Move to promises
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / blacklist.ts
CommitLineData
4d4e5cd4 1import * as express from 'express'
d33242b0 2
e02643f3 3import { database as db } from '../../../initializers/database'
65fcc311
C
4import { logger } from '../../../helpers'
5import {
6 authenticate,
7 ensureIsAdmin,
8 videosBlacklistValidator
9} from '../../../middlewares'
10
11const blacklistRouter = express.Router()
12
13blacklistRouter.post('/:id/blacklist',
14 authenticate,
15 ensureIsAdmin,
16 videosBlacklistValidator,
d33242b0
C
17 addVideoToBlacklist
18)
19
20// ---------------------------------------------------------------------------
21
65fcc311
C
22export {
23 blacklistRouter
24}
d33242b0
C
25
26// ---------------------------------------------------------------------------
27
69818c93 28function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
d33242b0
C
29 const videoInstance = res.locals.video
30
31 const toCreate = {
32 videoId: videoInstance.id
33 }
34
6fcd19ba
C
35 db.BlacklistedVideo.create(toCreate)
36 .then(() => res.type('json').status(204).end())
37 .catch(err => {
d33242b0
C
38 logger.error('Errors when blacklisting video ', { error: err })
39 return next(err)
6fcd19ba 40 })
d33242b0 41}