diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-17 10:50:33 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-18 15:42:20 +0100 |
commit | 1174a8479ab9ee47b3305d668fe757435057a298 (patch) | |
tree | 6d5e4702536c0d4b77c06ecab9e3db65c00d59d8 /server | |
parent | 6139124c673af2af02032905544909a2583dda2b (diff) | |
download | PeerTube-1174a8479ab9ee47b3305d668fe757435057a298.tar.gz PeerTube-1174a8479ab9ee47b3305d668fe757435057a298.tar.zst PeerTube-1174a8479ab9ee47b3305d668fe757435057a298.zip |
Set sort refractoring
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/accounts.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/jobs.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 8 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 8 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/channel.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 6 | ||||
-rw-r--r-- | server/middlewares/sort.ts | 62 |
9 files changed, 25 insertions, 81 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index aded581a5..3bc929db8 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects } from '../../helpers/utils' | 2 | import { getFormattedObjects } from '../../helpers/utils' |
3 | import { asyncMiddleware, paginationValidator, setAccountsSort, setPagination } from '../../middlewares' | 3 | import { asyncMiddleware, paginationValidator, setDefaultSort, setPagination } from '../../middlewares' |
4 | import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' | 4 | import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' |
5 | import { AccountModel } from '../../models/account/account' | 5 | import { AccountModel } from '../../models/account/account' |
6 | 6 | ||
@@ -9,7 +9,7 @@ const accountsRouter = express.Router() | |||
9 | accountsRouter.get('/', | 9 | accountsRouter.get('/', |
10 | paginationValidator, | 10 | paginationValidator, |
11 | accountsSortValidator, | 11 | accountsSortValidator, |
12 | setAccountsSort, | 12 | setDefaultSort, |
13 | setPagination, | 13 | setPagination, |
14 | asyncMiddleware(listAccounts) | 14 | asyncMiddleware(listAccounts) |
15 | ) | 15 | ) |
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index d9d6030a4..180a3fca6 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../shared/models/users' | 2 | import { UserRight } from '../../../shared/models/users' |
3 | import { getFormattedObjects } from '../../helpers/utils' | 3 | import { getFormattedObjects } from '../../helpers/utils' |
4 | import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' | 4 | import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultSort, setPagination } from '../../middlewares' |
5 | import { paginationValidator } from '../../middlewares/validators' | 5 | import { paginationValidator } from '../../middlewares/validators' |
6 | import { JobModel } from '../../models/job/job' | 6 | import { JobModel } from '../../models/job/job' |
7 | 7 | ||
@@ -12,7 +12,7 @@ jobsRouter.get('/', | |||
12 | ensureUserHasRight(UserRight.MANAGE_JOBS), | 12 | ensureUserHasRight(UserRight.MANAGE_JOBS), |
13 | paginationValidator, | 13 | paginationValidator, |
14 | jobsSortValidator, | 14 | jobsSortValidator, |
15 | setJobsSort, | 15 | setDefaultSort, |
16 | setPagination, | 16 | setPagination, |
17 | asyncMiddleware(listJobs) | 17 | asyncMiddleware(listJobs) |
18 | ) | 18 | ) |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index b93d8a816..0fbcc4b80 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -9,8 +9,8 @@ import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../ | |||
9 | import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' | 9 | import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' |
10 | import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' | 10 | import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' |
11 | import { | 11 | import { |
12 | asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, | 12 | asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, setDefaultSort, |
13 | setFollowersSort, setFollowingSort, setPagination | 13 | setPagination |
14 | } from '../../../middlewares' | 14 | } from '../../../middlewares' |
15 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' | 15 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' |
16 | import { ActorModel } from '../../../models/activitypub/actor' | 16 | import { ActorModel } from '../../../models/activitypub/actor' |
@@ -21,7 +21,7 @@ const serverFollowsRouter = express.Router() | |||
21 | serverFollowsRouter.get('/following', | 21 | serverFollowsRouter.get('/following', |
22 | paginationValidator, | 22 | paginationValidator, |
23 | followingSortValidator, | 23 | followingSortValidator, |
24 | setFollowingSort, | 24 | setDefaultSort, |
25 | setPagination, | 25 | setPagination, |
26 | asyncMiddleware(listFollowing) | 26 | asyncMiddleware(listFollowing) |
27 | ) | 27 | ) |
@@ -44,7 +44,7 @@ serverFollowsRouter.delete('/following/:host', | |||
44 | serverFollowsRouter.get('/followers', | 44 | serverFollowsRouter.get('/followers', |
45 | paginationValidator, | 45 | paginationValidator, |
46 | followersSortValidator, | 46 | followersSortValidator, |
47 | setFollowersSort, | 47 | setDefaultSort, |
48 | setPagination, | 48 | setPagination, |
49 | asyncMiddleware(listFollowers) | 49 | asyncMiddleware(listFollowers) |
50 | ) | 50 | ) |
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 5374c4b6a..0ca9b337a 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -12,8 +12,8 @@ import { updateActorAvatarInstance } from '../../lib/activitypub' | |||
12 | import { sendUpdateUser } from '../../lib/activitypub/send' | 12 | import { sendUpdateUser } from '../../lib/activitypub/send' |
13 | import { createUserAccountAndChannel } from '../../lib/user' | 13 | import { createUserAccountAndChannel } from '../../lib/user' |
14 | import { | 14 | import { |
15 | asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort, | 15 | asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setDefaultSort, |
16 | setVideosSort, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, | 16 | setPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, |
17 | usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator | 17 | usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator |
18 | } from '../../middlewares' | 18 | } from '../../middlewares' |
19 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' | 19 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' |
@@ -39,7 +39,7 @@ usersRouter.get('/me/videos', | |||
39 | authenticate, | 39 | authenticate, |
40 | paginationValidator, | 40 | paginationValidator, |
41 | videosSortValidator, | 41 | videosSortValidator, |
42 | setVideosSort, | 42 | setDefaultSort, |
43 | setPagination, | 43 | setPagination, |
44 | asyncMiddleware(getUserVideos) | 44 | asyncMiddleware(getUserVideos) |
45 | ) | 45 | ) |
@@ -55,7 +55,7 @@ usersRouter.get('/', | |||
55 | ensureUserHasRight(UserRight.MANAGE_USERS), | 55 | ensureUserHasRight(UserRight.MANAGE_USERS), |
56 | paginationValidator, | 56 | paginationValidator, |
57 | usersSortValidator, | 57 | usersSortValidator, |
58 | setUsersSort, | 58 | setDefaultSort, |
59 | setPagination, | 59 | setPagination, |
60 | asyncMiddleware(listUsers) | 60 | asyncMiddleware(listUsers) |
61 | ) | 61 | ) |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index e78f0f6fc..91594490b 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -6,8 +6,8 @@ import { getFormattedObjects } from '../../../helpers/utils' | |||
6 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | 7 | import { sendVideoAbuse } from '../../../lib/activitypub/send' |
8 | import { | 8 | import { |
9 | asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setPagination, setVideoAbusesSort, | 9 | asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setPagination, videoAbuseReportValidator, |
10 | videoAbuseReportValidator, videoAbusesSortValidator | 10 | videoAbusesSortValidator |
11 | } from '../../../middlewares' | 11 | } from '../../../middlewares' |
12 | import { AccountModel } from '../../../models/account/account' | 12 | import { AccountModel } from '../../../models/account/account' |
13 | import { VideoModel } from '../../../models/video/video' | 13 | import { VideoModel } from '../../../models/video/video' |
@@ -20,7 +20,7 @@ abuseVideoRouter.get('/abuse', | |||
20 | ensureUserHasRight(UserRight.MANAGE_VIDEO_ABUSES), | 20 | ensureUserHasRight(UserRight.MANAGE_VIDEO_ABUSES), |
21 | paginationValidator, | 21 | paginationValidator, |
22 | videoAbusesSortValidator, | 22 | videoAbusesSortValidator, |
23 | setVideoAbusesSort, | 23 | setDefaultSort, |
24 | setPagination, | 24 | setPagination, |
25 | asyncMiddleware(listVideoAbuses) | 25 | asyncMiddleware(listVideoAbuses) |
26 | ) | 26 | ) |
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 7c62b5476..2012575c8 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts | |||
@@ -7,7 +7,7 @@ import { sequelizeTypescript } from '../../../initializers' | |||
7 | import { setAsyncActorKeys } from '../../../lib/activitypub' | 7 | import { setAsyncActorKeys } from '../../../lib/activitypub' |
8 | import { createVideoChannel } from '../../../lib/video-channel' | 8 | import { createVideoChannel } from '../../../lib/video-channel' |
9 | import { | 9 | import { |
10 | asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setPagination, setVideoChannelsSort, | 10 | asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setPagination, |
11 | videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, | 11 | videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, |
12 | videoChannelsUpdateValidator | 12 | videoChannelsUpdateValidator |
13 | } from '../../../middlewares' | 13 | } from '../../../middlewares' |
@@ -19,7 +19,7 @@ const videoChannelRouter = express.Router() | |||
19 | videoChannelRouter.get('/channels', | 19 | videoChannelRouter.get('/channels', |
20 | paginationValidator, | 20 | paginationValidator, |
21 | videoChannelsSortValidator, | 21 | videoChannelsSortValidator, |
22 | setVideoChannelsSort, | 22 | setDefaultSort, |
23 | setPagination, | 23 | setPagination, |
24 | asyncMiddleware(listVideoChannels) | 24 | asyncMiddleware(listVideoChannels) |
25 | ) | 25 | ) |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 65fcf6b35..3c2727530 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -6,7 +6,7 @@ import { logger } from '../../../helpers/logger' | |||
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { sequelizeTypescript } from '../../../initializers' | 7 | import { sequelizeTypescript } from '../../../initializers' |
8 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' | 8 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' |
9 | import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' | 9 | import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination } from '../../../middlewares' |
10 | import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' | 10 | import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' |
11 | import { | 11 | import { |
12 | addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, | 12 | addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, |
@@ -20,7 +20,7 @@ const videoCommentRouter = express.Router() | |||
20 | videoCommentRouter.get('/:videoId/comment-threads', | 20 | videoCommentRouter.get('/:videoId/comment-threads', |
21 | paginationValidator, | 21 | paginationValidator, |
22 | videoCommentThreadsSortValidator, | 22 | videoCommentThreadsSortValidator, |
23 | setVideoCommentThreadsSort, | 23 | setDefaultSort, |
24 | setPagination, | 24 | setPagination, |
25 | asyncMiddleware(listVideoCommentThreadsValidator), | 25 | asyncMiddleware(listVideoCommentThreadsValidator), |
26 | asyncMiddleware(listVideoThreads) | 26 | asyncMiddleware(listVideoThreads) |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 368327914..6a7f1f184 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -14,7 +14,7 @@ import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer | |||
14 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' | 14 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' |
15 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' | 15 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' |
16 | import { | 16 | import { |
17 | asyncMiddleware, authenticate, paginationValidator, setPagination, setVideosSort, videosAddValidator, videosGetValidator, | 17 | asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination, videosAddValidator, videosGetValidator, |
18 | videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator | 18 | videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator |
19 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
20 | import { TagModel } from '../../../models/video/tag' | 20 | import { TagModel } from '../../../models/video/tag' |
@@ -44,7 +44,7 @@ videosRouter.get('/privacies', listVideoPrivacies) | |||
44 | videosRouter.get('/', | 44 | videosRouter.get('/', |
45 | paginationValidator, | 45 | paginationValidator, |
46 | videosSortValidator, | 46 | videosSortValidator, |
47 | setVideosSort, | 47 | setDefaultSort, |
48 | setPagination, | 48 | setPagination, |
49 | asyncMiddleware(listVideos) | 49 | asyncMiddleware(listVideos) |
50 | ) | 50 | ) |
@@ -52,7 +52,7 @@ videosRouter.get('/search', | |||
52 | videosSearchValidator, | 52 | videosSearchValidator, |
53 | paginationValidator, | 53 | paginationValidator, |
54 | videosSortValidator, | 54 | videosSortValidator, |
55 | setVideosSort, | 55 | setDefaultSort, |
56 | setPagination, | 56 | setPagination, |
57 | asyncMiddleware(searchVideos) | 57 | asyncMiddleware(searchVideos) |
58 | ) | 58 | ) |
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 4f524b49a..cdb809e75 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts | |||
@@ -2,55 +2,7 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { SortType } from '../helpers/utils' | 3 | import { SortType } from '../helpers/utils' |
4 | 4 | ||
5 | function setAccountsSort (req: express.Request, res: express.Response, next: express.NextFunction) { | 5 | function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
6 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
7 | |||
8 | return next() | ||
9 | } | ||
10 | |||
11 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
12 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
13 | |||
14 | return next() | ||
15 | } | ||
16 | |||
17 | function setJobsSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
18 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
19 | |||
20 | return next() | ||
21 | } | ||
22 | |||
23 | function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
24 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
25 | |||
26 | return next() | ||
27 | } | ||
28 | |||
29 | function setVideoChannelsSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
30 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
31 | |||
32 | return next() | ||
33 | } | ||
34 | |||
35 | function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
36 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
37 | |||
38 | return next() | ||
39 | } | ||
40 | |||
41 | function setVideoCommentThreadsSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
42 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
43 | |||
44 | return next() | ||
45 | } | ||
46 | |||
47 | function setFollowersSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
48 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
49 | |||
50 | return next() | ||
51 | } | ||
52 | |||
53 | function setFollowingSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
54 | if (!req.query.sort) req.query.sort = '-createdAt' | 6 | if (!req.query.sort) req.query.sort = '-createdAt' |
55 | 7 | ||
56 | return next() | 8 | return next() |
@@ -80,14 +32,6 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex | |||
80 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
81 | 33 | ||
82 | export { | 34 | export { |
83 | setUsersSort, | 35 | setDefaultSort, |
84 | setVideoAbusesSort, | 36 | setBlacklistSort |
85 | setVideoChannelsSort, | ||
86 | setVideosSort, | ||
87 | setBlacklistSort, | ||
88 | setFollowersSort, | ||
89 | setFollowingSort, | ||
90 | setJobsSort, | ||
91 | setVideoCommentThreadsSort, | ||
92 | setAccountsSort | ||
93 | } | 37 | } |