1
0
Fork 0
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:
Chocobozzz 2021-10-19 09:10:01 +02:00
parent 9c58375c08
commit 9593a78ae1
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 59 additions and 80 deletions

View file

@ -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
}