From d33242b047c68ae81c9657d05893d1838f1b1c89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 May 2017 16:53:35 +0200 Subject: Server: split videos controller --- server/controllers/api/videos/blacklist.js | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 server/controllers/api/videos/blacklist.js (limited to 'server/controllers/api/videos/blacklist.js') diff --git a/server/controllers/api/videos/blacklist.js b/server/controllers/api/videos/blacklist.js new file mode 100644 index 000000000..8c3e2a69d --- /dev/null +++ b/server/controllers/api/videos/blacklist.js @@ -0,0 +1,43 @@ +'use strict' + +const express = require('express') + +const db = require('../../../initializers/database') +const logger = require('../../../helpers/logger') +const middlewares = require('../../../middlewares') +const admin = middlewares.admin +const oAuth = middlewares.oauth +const validators = middlewares.validators +const validatorsVideos = validators.videos + +const router = express.Router() + +router.post('/:id/blacklist', + oAuth.authenticate, + admin.ensureIsAdmin, + validatorsVideos.videosBlacklist, + addVideoToBlacklist +) + +// --------------------------------------------------------------------------- + +module.exports = router + +// --------------------------------------------------------------------------- + +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() + }) +} -- cgit v1.2.3