2017-06-05 14:53:49 -05:00
|
|
|
import * as express from 'express'
|
2017-05-05 09:53:35 -05:00
|
|
|
|
2017-05-22 13:58:25 -05:00
|
|
|
import { database as db } from '../../../initializers/database'
|
2017-05-15 15:22:03 -05: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 09:53:35 -05:00
|
|
|
addVideoToBlacklist
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
export {
|
|
|
|
blacklistRouter
|
|
|
|
}
|
2017-05-05 09:53:35 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-06-10 15:15:25 -05:00
|
|
|
function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
|
2017-05-05 09:53:35 -05:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|