1
0
Fork 0
peertube/server/middlewares/sort.ts
2023-01-10 11:56:08 +01:00

29 lines
852 B
TypeScript

import express from 'express'
const setDefaultSort = setDefaultSortFactory('-createdAt')
const setDefaultVideosSort = setDefaultSortFactory('-publishedAt')
const setDefaultVideoRedundanciesSort = setDefaultSortFactory('name')
const setDefaultSearchSort = setDefaultSortFactory('-match')
const setBlacklistSort = setDefaultSortFactory('-createdAt')
// ---------------------------------------------------------------------------
export {
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()
}
}