aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/customValidators.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-07-01 16:22:36 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-07-01 16:22:36 +0200
commit5f698b82c7055df763f3830882ac5bad1397db23 (patch)
tree97e2e8178a5c7eec8e8f0e0cfce9cff399452cdc /server/helpers/customValidators.js
parentfc51fde048f2c3ce1dd3e85f5528335040bae894 (diff)
downloadPeerTube-5f698b82c7055df763f3830882ac5bad1397db23.tar.gz
PeerTube-5f698b82c7055df763f3830882ac5bad1397db23.tar.zst
PeerTube-5f698b82c7055df763f3830882ac5bad1397db23.zip
Use dashes for filenames
Diffstat (limited to 'server/helpers/customValidators.js')
-rw-r--r--server/helpers/customValidators.js114
1 files changed, 0 insertions, 114 deletions
diff --git a/server/helpers/customValidators.js b/server/helpers/customValidators.js
deleted file mode 100644
index b666644c0..000000000
--- a/server/helpers/customValidators.js
+++ /dev/null
@@ -1,114 +0,0 @@
1'use strict'
2
3const validator = require('express-validator').validator
4
5const constants = require('../initializers/constants')
6const VIDEOS_CONSTRAINTS_FIELDS = constants.VIDEOS_CONSTRAINTS_FIELDS
7
8const customValidators = {
9 exists: exists,
10 isEachRemoteVideosValid: isEachRemoteVideosValid,
11 isArray: isArray,
12 isVideoAuthorValid: isVideoAuthorValid,
13 isVideoDateValid: isVideoDateValid,
14 isVideoDescriptionValid: isVideoDescriptionValid,
15 isVideoDurationValid: isVideoDurationValid,
16 isVideoMagnetUriValid: isVideoMagnetUriValid,
17 isVideoNameValid: isVideoNameValid,
18 isVideoPodUrlValid: isVideoPodUrlValid,
19 isVideoTagsValid: isVideoTagsValid,
20 isVideoThumbnailValid: isVideoThumbnailValid,
21 isVideoThumbnail64Valid: isVideoThumbnail64Valid
22}
23
24function exists (value) {
25 return value !== undefined && value !== null
26}
27
28function isEachRemoteVideosValid (requests) {
29 return requests.every(function (request) {
30 const video = request.data
31 return (
32 isRequestTypeAddValid(request.type) &&
33 isVideoAuthorValid(video.author) &&
34 isVideoDateValid(video.createdDate) &&
35 isVideoDescriptionValid(video.description) &&
36 isVideoDurationValid(video.duration) &&
37 isVideoMagnetUriValid(video.magnetUri) &&
38 isVideoNameValid(video.name) &&
39 isVideoPodUrlValid(video.podUrl) &&
40 isVideoTagsValid(video.tags) &&
41 isVideoThumbnail64Valid(video.thumbnailBase64)
42 ) ||
43 (
44 isRequestTypeRemoveValid(request.type) &&
45 isVideoNameValid(video.name) &&
46 isVideoMagnetUriValid(video.magnetUri)
47 )
48 })
49}
50
51function isArray (value) {
52 return Array.isArray(value)
53}
54
55function isRequestTypeAddValid (value) {
56 return value === 'add'
57}
58
59function isRequestTypeRemoveValid (value) {
60 return value === 'remove'
61}
62
63function isVideoAuthorValid (value) {
64 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR)
65}
66
67function isVideoDateValid (value) {
68 return validator.isDate(value)
69}
70
71function isVideoDescriptionValid (value) {
72 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
73}
74
75function isVideoDurationValid (value) {
76 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION)
77}
78
79function isVideoMagnetUriValid (value) {
80 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.MAGNET_URI)
81}
82
83function isVideoNameValid (value) {
84 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
85}
86
87function isVideoPodUrlValid (value) {
88 // TODO: set options (TLD...)
89 return validator.isURL(value)
90}
91
92function isVideoTagsValid (tags) {
93 return isArray(tags) &&
94 validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
95 tags.every(function (tag) {
96 return validator.isAlphanumeric(tag) &&
97 validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
98 })
99}
100
101function isVideoThumbnailValid (value) {
102 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL)
103}
104
105function isVideoThumbnail64Valid (value) {
106 return validator.isBase64(value) &&
107 validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL64)
108}
109
110// ---------------------------------------------------------------------------
111
112module.exports = customValidators
113
114// ---------------------------------------------------------------------------