]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/sort.ts
Refactor model utils
[github/Chocobozzz/PeerTube.git] / server / middlewares / sort.ts
index 75238228fefb229401a6ef7491beb39f5e7e097d..77a532276d26de286b44ccb7c8700d82a4270504 100644 (file)
@@ -1,38 +1,19 @@
-import * as express from 'express'
-import { SortType } from '../models/utils'
+import express from 'express'
 
 const setDefaultSort = setDefaultSortFactory('-createdAt')
+const setDefaultVideosSort = setDefaultSortFactory('-publishedAt')
 
 const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
 
 const setDefaultSearchSort = setDefaultSortFactory('-match')
-
-function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
-  let 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 ...
-    newSort.sortModel = undefined
-  } else {
-    newSort.sortModel = 'Video'
-  }
-
-  newSort.sortValue = req.query.sort
-
-  req.query.sort = newSort
-
-  return next()
-}
+const setBlacklistSort = setDefaultSortFactory('-createdAt')
 
 // ---------------------------------------------------------------------------
 
 export {
   setDefaultSort,
   setDefaultSearchSort,
+  setDefaultVideosSort,
   setDefaultVideoRedundanciesSort,
   setBlacklistSort
 }