aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorGreen-Star <Green-Star@users.noreply.github.com>2017-09-22 09:13:43 +0200
committerBigard Florian <florian.bigard@gmail.com>2017-09-22 09:13:43 +0200
commit792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch)
treef7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/controllers
parentc9d6d155c397d0da0cb2d50064264fc1716f0501 (diff)
downloadPeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.gz
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.zst
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.zip
Handle blacklist (#84)
* Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/blacklist.ts60
-rw-r--r--server/controllers/api/index.ts2
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 @@
1import * as express from 'express'
2
3import { database } from '../../initializers'
4import { getFormattedObjects } from '../../helpers'
5import { BlacklistedVideo } from '../../../shared'
6import { BlacklistedVideoInstance } from '../../models'
7
8import {
9 removeVideoFromBlacklist
10} from '../../lib'
11import {
12 authenticate,
13 ensureIsAdmin,
14 paginationValidator,
15 blacklistSortValidator,
16 setBlacklistSort,
17 setPagination,
18 blacklistRemoveValidator
19} from '../../middlewares'
20
21const blacklistRouter = express.Router()
22
23blacklistRouter.get('/',
24 authenticate,
25 ensureIsAdmin,
26 paginationValidator,
27 blacklistSortValidator,
28 setBlacklistSort,
29 setPagination,
30 listBlacklist
31)
32
33blacklistRouter.delete('/:id',
34 authenticate,
35 ensureIsAdmin,
36 blacklistRemoveValidator,
37 removeVideoFromBlacklistController
38)
39
40// ---------------------------------------------------------------------------
41
42export {
43 blacklistRouter
44}
45
46// ---------------------------------------------------------------------------
47
48function 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
54function 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'
9import { requestSchedulerRouter } from './request-schedulers' 9import { requestSchedulerRouter } from './request-schedulers'
10import { usersRouter } from './users' 10import { usersRouter } from './users'
11import { videosRouter } from './videos' 11import { videosRouter } from './videos'
12import { blacklistRouter } from './blacklist'
12 13
13const apiRouter = express.Router() 14const apiRouter = express.Router()
14 15
@@ -19,6 +20,7 @@ apiRouter.use('/remote', remoteRouter)
19apiRouter.use('/request-schedulers', requestSchedulerRouter) 20apiRouter.use('/request-schedulers', requestSchedulerRouter)
20apiRouter.use('/users', usersRouter) 21apiRouter.use('/users', usersRouter)
21apiRouter.use('/videos', videosRouter) 22apiRouter.use('/videos', videosRouter)
23apiRouter.use('/blacklist', blacklistRouter)
22apiRouter.use('/ping', pong) 24apiRouter.use('/ping', pong)
23apiRouter.use('/*', badRequest) 25apiRouter.use('/*', badRequest)
24 26