aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-20 14:35:18 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commitd525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch)
tree4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/helpers
parent57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff)
downloadPeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip
Add videos list filters
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/misc.ts7
-rw-r--r--server/helpers/custom-validators/search.ts19
-rw-r--r--server/helpers/express-utils.ts14
3 files changed, 36 insertions, 4 deletions
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) {
41 return value 41 return value
42} 42}
43 43
44function toArray (value: string) {
45 if (value && isArray(value) === false) return [ value ]
46
47 return value
48}
49
44function isFileValid ( 50function isFileValid (
45 files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], 51 files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
46 mimeTypeRegex: string, 52 mimeTypeRegex: string,
@@ -80,5 +86,6 @@ export {
80 toValueOrNull, 86 toValueOrNull,
81 isBooleanValid, 87 isBooleanValid,
82 toIntOrNull, 88 toIntOrNull,
89 toArray,
83 isFileValid 90 isFileValid
84} 91}
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 @@
1import * as validator from 'validator'
2import 'express-validator'
3
4import { isArray } from './misc'
5
6function isNumberArray (value: any) {
7 return isArray(value) && value.every(v => validator.isInt('' + v))
8}
9
10function isStringArray (value: any) {
11 return isArray(value) && value.every(v => typeof v === 'string')
12}
13
14// ---------------------------------------------------------------------------
15
16export {
17 isNumberArray,
18 isStringArray
19}
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index d023117a8..5bf1e1a5f 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -5,13 +5,19 @@ import { logger } from './logger'
5import { User } from '../../shared/models/users' 5import { User } from '../../shared/models/users'
6import { generateRandomString } from './utils' 6import { generateRandomString } from './utils'
7 7
8function isNSFWHidden (res: express.Response) { 8function buildNSFWFilter (res: express.Response, paramNSFW?: boolean) {
9 if (paramNSFW === true || paramNSFW === false) return paramNSFW
10
9 if (res.locals.oauth) { 11 if (res.locals.oauth) {
10 const user: User = res.locals.oauth.token.User 12 const user: User = res.locals.oauth.token.User
11 if (user) return user.nsfwPolicy === 'do_not_list' 13 // User does not want NSFW videos
14 if (user && user.nsfwPolicy === 'do_not_list') return false
12 } 15 }
13 16
14 return CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' 17 if (CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list') return false
18
19 // Display all
20 return null
15} 21}
16 22
17function getHostWithPort (host: string) { 23function getHostWithPort (host: string) {
@@ -70,7 +76,7 @@ function createReqFiles (
70// --------------------------------------------------------------------------- 76// ---------------------------------------------------------------------------
71 77
72export { 78export {
73 isNSFWHidden, 79 buildNSFWFilter,
74 getHostWithPort, 80 getHostWithPort,
75 badRequest, 81 badRequest,
76 createReqFiles 82 createReqFiles