mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Refactor sort middlewares
This commit is contained in:
parent
9c58375c08
commit
9593a78ae1
4 changed files with 59 additions and 80 deletions
|
@ -22,26 +22,6 @@ function areValidationErrors (req: express.Request, res: express.Response) {
|
|||
return false
|
||||
}
|
||||
|
||||
function checkSort (sortableColumns: string[], tags: string[] = []) {
|
||||
return [
|
||||
query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking sort parameters', { parameters: req.query, tags })
|
||||
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
return next()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function createSortableColumns (sortableColumns: string[]) {
|
||||
const sortableColumnDesc = sortableColumns.map(sortableColumn => '-' + sortableColumn)
|
||||
|
||||
return sortableColumns.concat(sortableColumnDesc)
|
||||
}
|
||||
|
||||
function isValidVideoIdParam (paramName: string) {
|
||||
return param(paramName)
|
||||
.customSanitizer(toCompleteUUID)
|
||||
|
@ -58,8 +38,6 @@ function isValidPlaylistIdParam (paramName: string) {
|
|||
|
||||
export {
|
||||
areValidationErrors,
|
||||
checkSort,
|
||||
createSortableColumns,
|
||||
isValidVideoIdParam,
|
||||
isValidPlaylistIdParam
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue