aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/helpers/custom-validators/videos.js
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/helpers/custom-validators/videos.js')
-rw-r--r--server/helpers/custom-validators/videos.js148
1 files changed, 0 insertions, 148 deletions
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
deleted file mode 100644
index 196731e04..000000000
--- a/server/helpers/custom-validators/videos.js
+++ /dev/null
@@ -1,148 +0,0 @@
1'use strict'
2
3const validator = require('express-validator').validator
4const values = require('lodash/values')
5
6const constants = require('../../initializers/constants')
7const usersValidators = require('./users')
8const miscValidators = require('./misc')
9const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS
10const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES
11const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENTS
12
13const videosValidators = {
14 isVideoAuthorValid,
15 isVideoDateValid,
16 isVideoCategoryValid,
17 isVideoLicenceValid,
18 isVideoLanguageValid,
19 isVideoNSFWValid,
20 isVideoDescriptionValid,
21 isVideoDurationValid,
22 isVideoInfoHashValid,
23 isVideoNameValid,
24 isVideoTagsValid,
25 isVideoThumbnailValid,
26 isVideoThumbnailDataValid,
27 isVideoExtnameValid,
28 isVideoRemoteIdValid,
29 isVideoAbuseReasonValid,
30 isVideoAbuseReporterUsernameValid,
31 isVideoFile,
32 isVideoViewsValid,
33 isVideoLikesValid,
34 isVideoRatingTypeValid,
35 isVideoDislikesValid,
36 isVideoEventCountValid
37}
38
39function isVideoAuthorValid (value) {
40 return usersValidators.isUserUsernameValid(value)
41}
42
43function isVideoDateValid (value) {
44 return validator.isDate(value)
45}
46
47function isVideoCategoryValid (value) {
48 return constants.VIDEO_CATEGORIES[value] !== undefined
49}
50
51function isVideoLicenceValid (value) {
52 return constants.VIDEO_LICENCES[value] !== undefined
53}
54
55function isVideoLanguageValid (value) {
56 return value === null || constants.VIDEO_LANGUAGES[value] !== undefined
57}
58
59function isVideoNSFWValid (value) {
60 return validator.isBoolean(value)
61}
62
63function isVideoDescriptionValid (value) {
64 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
65}
66
67function isVideoDurationValid (value) {
68 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION)
69}
70
71function isVideoExtnameValid (value) {
72 return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1
73}
74
75function isVideoInfoHashValid (value) {
76 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
77}
78
79function isVideoNameValid (value) {
80 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
81}
82
83function isVideoTagsValid (tags) {
84 return miscValidators.isArray(tags) &&
85 validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
86 tags.every(function (tag) {
87 return validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
88 })
89}
90
91function isVideoThumbnailValid (value) {
92 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL)
93}
94
95function isVideoThumbnailDataValid (value) {
96 return validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA)
97}
98
99function isVideoRemoteIdValid (value) {
100 return validator.isUUID(value, 4)
101}
102
103function isVideoAbuseReasonValid (value) {
104 return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
105}
106
107function isVideoAbuseReporterUsernameValid (value) {
108 return usersValidators.isUserUsernameValid(value)
109}
110
111function isVideoViewsValid (value) {
112 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS)
113}
114
115function isVideoLikesValid (value) {
116 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.LIKES)
117}
118
119function isVideoDislikesValid (value) {
120 return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DISLIKES)
121}
122
123function isVideoEventCountValid (value) {
124 return validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT)
125}
126
127function isVideoRatingTypeValid (value) {
128 return values(constants.VIDEO_RATE_TYPES).indexOf(value) !== -1
129}
130
131function isVideoFile (value, files) {
132 // Should have files
133 if (!files) return false
134
135 // Should have videofile file
136 const videofile = files.videofile
137 if (!videofile || videofile.length === 0) return false
138
139 // The file should exist
140 const file = videofile[0]
141 if (!file || !file.originalname) return false
142
143 return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
144}
145
146// ---------------------------------------------------------------------------
147
148module.exports = videosValidators