diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/blacklist.ts | 60 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 2 |
2 files changed, 62 insertions, 0 deletions
diff --git a/server/controllers/api/blacklist.ts b/server/controllers/api/blacklist.ts new file mode 100644 index 000000000..9b2d8017e --- /dev/null +++ b/server/controllers/api/blacklist.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | import * as express from 'express' | ||
2 | |||
3 | import { database } from '../../initializers' | ||
4 | import { getFormattedObjects } from '../../helpers' | ||
5 | import { BlacklistedVideo } from '../../../shared' | ||
6 | import { BlacklistedVideoInstance } from '../../models' | ||
7 | |||
8 | import { | ||
9 | removeVideoFromBlacklist | ||
10 | } from '../../lib' | ||
11 | import { | ||
12 | authenticate, | ||
13 | ensureIsAdmin, | ||
14 | paginationValidator, | ||
15 | blacklistSortValidator, | ||
16 | setBlacklistSort, | ||
17 | setPagination, | ||
18 | blacklistRemoveValidator | ||
19 | } from '../../middlewares' | ||
20 | |||
21 | const blacklistRouter = express.Router() | ||
22 | |||
23 | blacklistRouter.get('/', | ||
24 | authenticate, | ||
25 | ensureIsAdmin, | ||
26 | paginationValidator, | ||
27 | blacklistSortValidator, | ||
28 | setBlacklistSort, | ||
29 | setPagination, | ||
30 | listBlacklist | ||
31 | ) | ||
32 | |||
33 | blacklistRouter.delete('/:id', | ||
34 | authenticate, | ||
35 | ensureIsAdmin, | ||
36 | blacklistRemoveValidator, | ||
37 | removeVideoFromBlacklistController | ||
38 | ) | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | export { | ||
43 | blacklistRouter | ||
44 | } | ||
45 | |||
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
49 | database.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort) | ||
50 | .then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total))) | ||
51 | .catch(err => next(err)) | ||
52 | } | ||
53 | |||
54 | function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
55 | const entry = res.locals.blacklistEntryToRemove as BlacklistedVideoInstance | ||
56 | |||
57 | removeVideoFromBlacklist(entry) | ||
58 | .then(() => res.sendStatus(204)) | ||
59 | .catch(err => next(err)) | ||
60 | } | ||
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index a9205b33c..fdc887915 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -9,6 +9,7 @@ import { remoteRouter } from './remote' | |||
9 | import { requestSchedulerRouter } from './request-schedulers' | 9 | import { requestSchedulerRouter } from './request-schedulers' |
10 | import { usersRouter } from './users' | 10 | import { usersRouter } from './users' |
11 | import { videosRouter } from './videos' | 11 | import { videosRouter } from './videos' |
12 | import { blacklistRouter } from './blacklist' | ||
12 | 13 | ||
13 | const apiRouter = express.Router() | 14 | const apiRouter = express.Router() |
14 | 15 | ||
@@ -19,6 +20,7 @@ apiRouter.use('/remote', remoteRouter) | |||
19 | apiRouter.use('/request-schedulers', requestSchedulerRouter) | 20 | apiRouter.use('/request-schedulers', requestSchedulerRouter) |
20 | apiRouter.use('/users', usersRouter) | 21 | apiRouter.use('/users', usersRouter) |
21 | apiRouter.use('/videos', videosRouter) | 22 | apiRouter.use('/videos', videosRouter) |
23 | apiRouter.use('/blacklist', blacklistRouter) | ||
22 | apiRouter.use('/ping', pong) | 24 | apiRouter.use('/ping', pong) |
23 | apiRouter.use('/*', badRequest) | 25 | apiRouter.use('/*', badRequest) |
24 | 26 | ||