diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/controllers/api/videos/blacklist.ts | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/controllers/api/videos/blacklist.ts')
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts new file mode 100644 index 000000000..db6d95e73 --- /dev/null +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -0,0 +1,43 @@ | |||
1 | import express = require('express') | ||
2 | |||
3 | const db = require('../../../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 | } | ||