aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-17 10:50:33 +0100
committerChocobozzz <me@florianbigard.com>2018-01-18 15:42:20 +0100
commit1174a8479ab9ee47b3305d668fe757435057a298 (patch)
tree6d5e4702536c0d4b77c06ecab9e3db65c00d59d8 /server
parent6139124c673af2af02032905544909a2583dda2b (diff)
downloadPeerTube-1174a8479ab9ee47b3305d668fe757435057a298.tar.gz
PeerTube-1174a8479ab9ee47b3305d668fe757435057a298.tar.zst
PeerTube-1174a8479ab9ee47b3305d668fe757435057a298.zip
Set sort refractoring
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/accounts.ts4
-rw-r--r--server/controllers/api/jobs.ts4
-rw-r--r--server/controllers/api/server/follows.ts8
-rw-r--r--server/controllers/api/users.ts8
-rw-r--r--server/controllers/api/videos/abuse.ts6
-rw-r--r--server/controllers/api/videos/channel.ts4
-rw-r--r--server/controllers/api/videos/comment.ts4
-rw-r--r--server/controllers/api/videos/index.ts6
-rw-r--r--server/middlewares/sort.ts62
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils' 2import { getFormattedObjects } from '../../helpers/utils'
3import { asyncMiddleware, paginationValidator, setAccountsSort, setPagination } from '../../middlewares' 3import { asyncMiddleware, paginationValidator, setDefaultSort, setPagination } from '../../middlewares'
4import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' 4import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators'
5import { AccountModel } from '../../models/account/account' 5import { AccountModel } from '../../models/account/account'
6 6
@@ -9,7 +9,7 @@ const accountsRouter = express.Router()
9accountsRouter.get('/', 9accountsRouter.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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight } from '../../../shared/models/users' 2import { UserRight } from '../../../shared/models/users'
3import { getFormattedObjects } from '../../helpers/utils' 3import { getFormattedObjects } from '../../helpers/utils'
4import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' 4import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultSort, setPagination } from '../../middlewares'
5import { paginationValidator } from '../../middlewares/validators' 5import { paginationValidator } from '../../middlewares/validators'
6import { JobModel } from '../../models/job/job' 6import { 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 '../../../
9import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' 9import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor'
10import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' 10import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send'
11import { 11import {
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'
15import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' 15import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators'
16import { ActorModel } from '../../../models/activitypub/actor' 16import { ActorModel } from '../../../models/activitypub/actor'
@@ -21,7 +21,7 @@ const serverFollowsRouter = express.Router()
21serverFollowsRouter.get('/following', 21serverFollowsRouter.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',
44serverFollowsRouter.get('/followers', 44serverFollowsRouter.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'
12import { sendUpdateUser } from '../../lib/activitypub/send' 12import { sendUpdateUser } from '../../lib/activitypub/send'
13import { createUserAccountAndChannel } from '../../lib/user' 13import { createUserAccountAndChannel } from '../../lib/user'
14import { 14import {
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'
19import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' 19import { 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'
6import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
7import { sendVideoAbuse } from '../../../lib/activitypub/send' 7import { sendVideoAbuse } from '../../../lib/activitypub/send'
8import { 8import {
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'
12import { AccountModel } from '../../../models/account/account' 12import { AccountModel } from '../../../models/account/account'
13import { VideoModel } from '../../../models/video/video' 13import { 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'
7import { setAsyncActorKeys } from '../../../lib/activitypub' 7import { setAsyncActorKeys } from '../../../lib/activitypub'
8import { createVideoChannel } from '../../../lib/video-channel' 8import { createVideoChannel } from '../../../lib/video-channel'
9import { 9import {
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()
19videoChannelRouter.get('/channels', 19videoChannelRouter.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'
6import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
7import { sequelizeTypescript } from '../../../initializers' 7import { sequelizeTypescript } from '../../../initializers'
8import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' 8import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment'
9import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' 9import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination } from '../../../middlewares'
10import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' 10import { videoCommentThreadsSortValidator } from '../../../middlewares/validators'
11import { 11import {
12 addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, 12 addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator,
@@ -20,7 +20,7 @@ const videoCommentRouter = express.Router()
20videoCommentRouter.get('/:videoId/comment-threads', 20videoCommentRouter.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
14import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' 14import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
15import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' 15import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler'
16import { 16import {
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'
20import { TagModel } from '../../../models/video/tag' 20import { TagModel } from '../../../models/video/tag'
@@ -44,7 +44,7 @@ videosRouter.get('/privacies', listVideoPrivacies)
44videosRouter.get('/', 44videosRouter.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'
2import 'express-validator' 2import 'express-validator'
3import { SortType } from '../helpers/utils' 3import { SortType } from '../helpers/utils'
4 4
5function setAccountsSort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function 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
11function 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
17function 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
23function 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
29function 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
35function 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
41function 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
47function 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
53function 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
82export { 34export {
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}