2017-05-15 16:22:03 -04:00
|
|
|
import express = require('express')
|
2017-05-05 10:53:35 -04:00
|
|
|
|
|
|
|
const db = require('../../../initializers/database')
|
2017-05-15 16:22:03 -04:00
|
|
|
import { logger } from '../../../helpers'
|
|
|
|
import {
|
|
|
|
authenticate,
|
|
|
|
ensureIsAdmin,
|
|
|
|
videosBlacklistValidator
|
|
|
|
} from '../../../middlewares'
|
|
|
|
|
|
|
|
const blacklistRouter = express.Router()
|
|
|
|
|
|
|
|
blacklistRouter.post('/:id/blacklist',
|
|
|
|
authenticate,
|
|
|
|
ensureIsAdmin,
|
|
|
|
videosBlacklistValidator,
|
2017-05-05 10:53:35 -04:00
|
|
|
addVideoToBlacklist
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 16:22:03 -04:00
|
|
|
export {
|
|
|
|
blacklistRouter
|
|
|
|
}
|
2017-05-05 10:53:35 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|