]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/sort.ts
Increase captions max size
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
index 687ce097b7c8b2f32702df186fd63e8ceb7c1a94..4588958988af88a759c35ebfbc7a6afb58ed0643 100644 (file)
@@ -1,39 +1,25 @@
-import 'express-validator'
-import * as express from 'express'
+import express from 'express'
+import { SortType } from '../models/utils'
 
-import { SortType } from '../helpers'
-import { database } from '../initializers'
+const setDefaultSort = setDefaultSortFactory('-createdAt')
+const setDefaultVideosSort = setDefaultSortFactory('-publishedAt')
 
-function setUsersSort (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'
+const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
 
-  return next()
-}
-
-function setVideosSort (req: express.Request, res: express.Response, next: express.NextFunction) {
-  if (!req.query.sort) req.query.sort = '-createdAt'
-
-  return next()
-}
+const setDefaultSearchSort = setDefaultSortFactory('-match')
 
 function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
-  let newSort: SortType = { sortModel: undefined, sortValue: undefined }
+  const newSort: SortType = { sortModel: undefined, sortValue: '' }
 
   if (!req.query.sort) req.query.sort = '-createdAt'
 
   // Set model we want to sort onto
   if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
       req.query.sort === '-id' || req.query.sort === 'id') {
-    // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
+    // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter...
     newSort.sortModel = undefined
   } else {
-    newSort.sortModel = database.Video
+    newSort.sortModel = 'Video'
   }
 
   newSort.sortValue = req.query.sort
@@ -46,8 +32,19 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex
 // ---------------------------------------------------------------------------
 
 export {
-  setUsersSort,
-  setVideoAbusesSort,
-  setVideosSort,
+  setDefaultSort,
+  setDefaultSearchSort,
+  setDefaultVideosSort,
+  setDefaultVideoRedundanciesSort,
   setBlacklistSort
 }
+
+// ---------------------------------------------------------------------------
+
+function setDefaultSortFactory (sort: string) {
+  return (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    if (!req.query.sort) req.query.sort = sort
+
+    return next()
+  }
+}