aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/blacklist.ts54
1 files changed, 49 insertions, 5 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index d8f2068ec..66311598e 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -1,22 +1,46 @@
1import * as express from 'express' 1import * as express from 'express'
2 2
3import { database as db } from '../../../initializers/database' 3import { database as db } from '../../../initializers'
4import { logger } from '../../../helpers' 4import { logger, getFormattedObjects } from '../../../helpers'
5import { 5import {
6 authenticate, 6 authenticate,
7 ensureIsAdmin, 7 ensureIsAdmin,
8 videosBlacklistValidator 8 videosBlacklistAddValidator,
9 videosBlacklistRemoveValidator,
10 paginationValidator,
11 blacklistSortValidator,
12 setBlacklistSort,
13 setPagination
9} from '../../../middlewares' 14} from '../../../middlewares'
15import { BlacklistedVideoInstance } from '../../../models'
16import { BlacklistedVideo } from '../../../../shared'
10 17
11const blacklistRouter = express.Router() 18const blacklistRouter = express.Router()
12 19
13blacklistRouter.post('/:id/blacklist', 20blacklistRouter.post('/:videoId/blacklist',
14 authenticate, 21 authenticate,
15 ensureIsAdmin, 22 ensureIsAdmin,
16 videosBlacklistValidator, 23 videosBlacklistAddValidator,
17 addVideoToBlacklist 24 addVideoToBlacklist
18) 25)
19 26
27blacklistRouter.get('/blacklist',
28 authenticate,
29 ensureIsAdmin,
30 paginationValidator,
31 blacklistSortValidator,
32 setBlacklistSort,
33 setPagination,
34 listBlacklist
35)
36
37blacklistRouter.delete('/:videoId/blacklist',
38 authenticate,
39 ensureIsAdmin,
40 videosBlacklistRemoveValidator,
41 removeVideoFromBlacklistController
42)
43
20// --------------------------------------------------------------------------- 44// ---------------------------------------------------------------------------
21 45
22export { 46export {
@@ -39,3 +63,23 @@ function addVideoToBlacklist (req: express.Request, res: express.Response, next:
39 return next(err) 63 return next(err)
40 }) 64 })
41} 65}
66
67function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
68 db.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
69 .then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)))
70 .catch(err => next(err))
71}
72
73function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
74 const blacklistedVideo = res.locals.blacklistedVideo as BlacklistedVideoInstance
75
76 blacklistedVideo.destroy()
77 .then(() => {
78 logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
79 res.sendStatus(204)
80 })
81 .catch(err => {
82 logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, err)
83 next(err)
84 })
85}