From: Chocobozzz Date: Wed, 17 Jan 2018 09:50:33 +0000 (+0100) Subject: Set sort refractoring X-Git-Tag: v0.0.12-alpha~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1174a8479ab9ee47b3305d668fe757435057a298;p=oweals%2Fpeertube.git Set sort refractoring --- 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 @@ 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) ) 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 @@ 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) ) 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 '../../../ 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) ) 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' 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) ) 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' 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) ) 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' 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) ) 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' 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) 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 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) ) 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' 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 }