diff options
author | Green-Star <Green-Star@users.noreply.github.com> | 2017-09-22 09:13:43 +0200 |
---|---|---|
committer | Bigard Florian <florian.bigard@gmail.com> | 2017-09-22 09:13:43 +0200 |
commit | 792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch) | |
tree | f7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/middlewares/sort.ts | |
parent | c9d6d155c397d0da0cb2d50064264fc1716f0501 (diff) | |
download | PeerTube-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/middlewares/sort.ts')
-rw-r--r-- | server/middlewares/sort.ts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 632b2fae4..687ce097b 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts | |||
@@ -1,6 +1,9 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | 3 | ||
4 | import { SortType } from '../helpers' | ||
5 | import { database } from '../initializers' | ||
6 | |||
4 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { | 7 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
5 | if (!req.query.sort) req.query.sort = '-createdAt' | 8 | if (!req.query.sort) req.query.sort = '-createdAt' |
6 | 9 | ||
@@ -19,10 +22,32 @@ function setVideosSort (req: express.Request, res: express.Response, next: expre | |||
19 | return next() | 22 | return next() |
20 | } | 23 | } |
21 | 24 | ||
25 | function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
26 | let newSort: SortType = { sortModel: undefined, sortValue: undefined } | ||
27 | |||
28 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
29 | |||
30 | // Set model we want to sort onto | ||
31 | if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' || | ||
32 | req.query.sort === '-id' || req.query.sort === 'id') { | ||
33 | // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ... | ||
34 | newSort.sortModel = undefined | ||
35 | } else { | ||
36 | newSort.sortModel = database.Video | ||
37 | } | ||
38 | |||
39 | newSort.sortValue = req.query.sort | ||
40 | |||
41 | req.query.sort = newSort | ||
42 | |||
43 | return next() | ||
44 | } | ||
45 | |||
22 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
23 | 47 | ||
24 | export { | 48 | export { |
25 | setUsersSort, | 49 | setUsersSort, |
26 | setVideoAbusesSort, | 50 | setVideoAbusesSort, |
27 | setVideosSort | 51 | setVideosSort, |
52 | setBlacklistSort | ||
28 | } | 53 | } |