1
0
Fork 0

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 { 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 { AccountModel } from '../../models/account/account'
@ -9,7 +9,7 @@ const accountsRouter = express.Router()
accountsRouter.get('/',
paginationValidator,
accountsSortValidator,
setAccountsSort,
setDefaultSort,
setPagination,
asyncMiddleware(listAccounts)
)

View File

@ -1,7 +1,7 @@
import * as express from 'express'
import { UserRight } from '../../../shared/models/users'
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 { JobModel } from '../../models/job/job'
@ -12,7 +12,7 @@ jobsRouter.get('/',
ensureUserHasRight(UserRight.MANAGE_JOBS),
paginationValidator,
jobsSortValidator,
setJobsSort,
setDefaultSort,
setPagination,
asyncMiddleware(listJobs)
)

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import { logger } from '../../../helpers/logger'
import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers'
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 {
addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator,
@ -20,7 +20,7 @@ const videoCommentRouter = express.Router()
videoCommentRouter.get('/:videoId/comment-threads',
paginationValidator,
videoCommentThreadsSortValidator,
setVideoCommentThreadsSort,
setDefaultSort,
setPagination,
asyncMiddleware(listVideoCommentThreadsValidator),
asyncMiddleware(listVideoThreads)

View File

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

View File

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