Set sort refractoring

This commit is contained in:
Chocobozzz 2018-01-17 10:50:33 +01:00
parent 6139124c67
commit 1174a8479a
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 25 additions and 81 deletions

View File

@ -1,6 +1,6 @@
import * as express from 'express' import * as express from 'express'
import { getFormattedObjects } from '../../helpers/utils' import { getFormattedObjects } from '../../helpers/utils'
import { asyncMiddleware, paginationValidator, setAccountsSort, setPagination } from '../../middlewares' import { asyncMiddleware, paginationValidator, setDefaultSort, setPagination } from '../../middlewares'
import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account' import { AccountModel } from '../../models/account/account'
@ -9,7 +9,7 @@ const accountsRouter = express.Router()
accountsRouter.get('/', accountsRouter.get('/',
paginationValidator, paginationValidator,
accountsSortValidator, accountsSortValidator,
setAccountsSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listAccounts) asyncMiddleware(listAccounts)
) )

View File

@ -1,7 +1,7 @@
import * as express from 'express' import * as express from 'express'
import { UserRight } from '../../../shared/models/users' import { UserRight } from '../../../shared/models/users'
import { getFormattedObjects } from '../../helpers/utils' import { getFormattedObjects } from '../../helpers/utils'
import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares' import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultSort, setPagination } from '../../middlewares'
import { paginationValidator } from '../../middlewares/validators' import { paginationValidator } from '../../middlewares/validators'
import { JobModel } from '../../models/job/job' import { JobModel } from '../../models/job/job'
@ -12,7 +12,7 @@ jobsRouter.get('/',
ensureUserHasRight(UserRight.MANAGE_JOBS), ensureUserHasRight(UserRight.MANAGE_JOBS),
paginationValidator, paginationValidator,
jobsSortValidator, jobsSortValidator,
setJobsSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listJobs) asyncMiddleware(listJobs)
) )

View File

@ -9,8 +9,8 @@ import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../
import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor' import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor'
import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send'
import { import {
asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, setDefaultSort,
setFollowersSort, setFollowingSort, setPagination setPagination
} from '../../../middlewares' } from '../../../middlewares'
import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators'
import { ActorModel } from '../../../models/activitypub/actor' import { ActorModel } from '../../../models/activitypub/actor'
@ -21,7 +21,7 @@ const serverFollowsRouter = express.Router()
serverFollowsRouter.get('/following', serverFollowsRouter.get('/following',
paginationValidator, paginationValidator,
followingSortValidator, followingSortValidator,
setFollowingSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listFollowing) asyncMiddleware(listFollowing)
) )
@ -44,7 +44,7 @@ serverFollowsRouter.delete('/following/:host',
serverFollowsRouter.get('/followers', serverFollowsRouter.get('/followers',
paginationValidator, paginationValidator,
followersSortValidator, followersSortValidator,
setFollowersSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listFollowers) asyncMiddleware(listFollowers)
) )

View File

@ -12,8 +12,8 @@ import { updateActorAvatarInstance } from '../../lib/activitypub'
import { sendUpdateUser } from '../../lib/activitypub/send' import { sendUpdateUser } from '../../lib/activitypub/send'
import { createUserAccountAndChannel } from '../../lib/user' import { createUserAccountAndChannel } from '../../lib/user'
import { import {
asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort, asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setDefaultSort,
setVideosSort, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, setPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator,
usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator
} from '../../middlewares' } from '../../middlewares'
import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators'
@ -39,7 +39,7 @@ usersRouter.get('/me/videos',
authenticate, authenticate,
paginationValidator, paginationValidator,
videosSortValidator, videosSortValidator,
setVideosSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(getUserVideos) asyncMiddleware(getUserVideos)
) )
@ -55,7 +55,7 @@ usersRouter.get('/',
ensureUserHasRight(UserRight.MANAGE_USERS), ensureUserHasRight(UserRight.MANAGE_USERS),
paginationValidator, paginationValidator,
usersSortValidator, usersSortValidator,
setUsersSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listUsers) asyncMiddleware(listUsers)
) )

View File

@ -6,8 +6,8 @@ import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers' import { sequelizeTypescript } from '../../../initializers'
import { sendVideoAbuse } from '../../../lib/activitypub/send' import { sendVideoAbuse } from '../../../lib/activitypub/send'
import { import {
asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setPagination, setVideoAbusesSort, asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setPagination, videoAbuseReportValidator,
videoAbuseReportValidator, videoAbusesSortValidator videoAbusesSortValidator
} from '../../../middlewares' } from '../../../middlewares'
import { AccountModel } from '../../../models/account/account' import { AccountModel } from '../../../models/account/account'
import { VideoModel } from '../../../models/video/video' import { VideoModel } from '../../../models/video/video'
@ -20,7 +20,7 @@ abuseVideoRouter.get('/abuse',
ensureUserHasRight(UserRight.MANAGE_VIDEO_ABUSES), ensureUserHasRight(UserRight.MANAGE_VIDEO_ABUSES),
paginationValidator, paginationValidator,
videoAbusesSortValidator, videoAbusesSortValidator,
setVideoAbusesSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listVideoAbuses) asyncMiddleware(listVideoAbuses)
) )

View File

@ -7,7 +7,7 @@ import { sequelizeTypescript } from '../../../initializers'
import { setAsyncActorKeys } from '../../../lib/activitypub' import { setAsyncActorKeys } from '../../../lib/activitypub'
import { createVideoChannel } from '../../../lib/video-channel' import { createVideoChannel } from '../../../lib/video-channel'
import { import {
asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setPagination, setVideoChannelsSort, asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setPagination,
videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator,
videoChannelsUpdateValidator videoChannelsUpdateValidator
} from '../../../middlewares' } from '../../../middlewares'
@ -19,7 +19,7 @@ const videoChannelRouter = express.Router()
videoChannelRouter.get('/channels', videoChannelRouter.get('/channels',
paginationValidator, paginationValidator,
videoChannelsSortValidator, videoChannelsSortValidator,
setVideoChannelsSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listVideoChannels) asyncMiddleware(listVideoChannels)
) )

View File

@ -6,7 +6,7 @@ import { logger } from '../../../helpers/logger'
import { getFormattedObjects } from '../../../helpers/utils' import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers' import { sequelizeTypescript } from '../../../initializers'
import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment'
import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination } from '../../../middlewares'
import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' import { videoCommentThreadsSortValidator } from '../../../middlewares/validators'
import { import {
addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator,
@ -20,7 +20,7 @@ const videoCommentRouter = express.Router()
videoCommentRouter.get('/:videoId/comment-threads', videoCommentRouter.get('/:videoId/comment-threads',
paginationValidator, paginationValidator,
videoCommentThreadsSortValidator, videoCommentThreadsSortValidator,
setVideoCommentThreadsSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listVideoCommentThreadsValidator), asyncMiddleware(listVideoCommentThreadsValidator),
asyncMiddleware(listVideoThreads) asyncMiddleware(listVideoThreads)

View File

@ -14,7 +14,7 @@ import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer
import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler'
import { import {
asyncMiddleware, authenticate, paginationValidator, setPagination, setVideosSort, videosAddValidator, videosGetValidator, asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination, videosAddValidator, videosGetValidator,
videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator
} from '../../../middlewares' } from '../../../middlewares'
import { TagModel } from '../../../models/video/tag' import { TagModel } from '../../../models/video/tag'
@ -44,7 +44,7 @@ videosRouter.get('/privacies', listVideoPrivacies)
videosRouter.get('/', videosRouter.get('/',
paginationValidator, paginationValidator,
videosSortValidator, videosSortValidator,
setVideosSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(listVideos) asyncMiddleware(listVideos)
) )
@ -52,7 +52,7 @@ videosRouter.get('/search',
videosSearchValidator, videosSearchValidator,
paginationValidator, paginationValidator,
videosSortValidator, videosSortValidator,
setVideosSort, setDefaultSort,
setPagination, setPagination,
asyncMiddleware(searchVideos) asyncMiddleware(searchVideos)
) )

View File

@ -2,55 +2,7 @@ import * as express from 'express'
import 'express-validator' import 'express-validator'
import { SortType } from '../helpers/utils' import { SortType } from '../helpers/utils'
function setAccountsSort (req: express.Request, res: express.Response, next: express.NextFunction) { function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setJobsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setVideoAbusesSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setVideoChannelsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setVideoCommentThreadsSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setFollowersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt'
return next()
}
function setFollowingSort (req: express.Request, res: express.Response, next: express.NextFunction) {
if (!req.query.sort) req.query.sort = '-createdAt' if (!req.query.sort) req.query.sort = '-createdAt'
return next() return next()
@ -80,14 +32,6 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
setUsersSort, setDefaultSort,
setVideoAbusesSort, setBlacklistSort
setVideoChannelsSort,
setVideosSort,
setBlacklistSort,
setFollowersSort,
setFollowingSort,
setJobsSort,
setVideoCommentThreadsSort,
setAccountsSort
} }