From d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 20 Jul 2018 14:35:18 +0200 Subject: Add videos list filters --- server/helpers/custom-validators/misc.ts | 7 +++++++ server/helpers/custom-validators/search.ts | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 server/helpers/custom-validators/search.ts (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 455aae367..151fc852b 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -41,6 +41,12 @@ function toValueOrNull (value: string) { return value } +function toArray (value: string) { + if (value && isArray(value) === false) return [ value ] + + return value +} + function isFileValid ( files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], mimeTypeRegex: string, @@ -80,5 +86,6 @@ export { toValueOrNull, isBooleanValid, toIntOrNull, + toArray, isFileValid } diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.ts new file mode 100644 index 000000000..2fde39160 --- /dev/null +++ b/server/helpers/custom-validators/search.ts @@ -0,0 +1,19 @@ +import * as validator from 'validator' +import 'express-validator' + +import { isArray } from './misc' + +function isNumberArray (value: any) { + return isArray(value) && value.every(v => validator.isInt('' + v)) +} + +function isStringArray (value: any) { + return isArray(value) && value.every(v => typeof v === 'string') +} + +// --------------------------------------------------------------------------- + +export { + isNumberArray, + isStringArray +} -- cgit v1.2.3