diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 10 | ||||
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/plugins.ts | 22 | ||||
-rw-r--r-- | server/helpers/custom-validators/servers.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-studio.ts | 3 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 5 |
6 files changed, 28 insertions, 18 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 2a2f008b9..97b3577af 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -7,11 +7,11 @@ import { peertubeTruncate } from '../../core-utils' | |||
7 | import { isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc' | 7 | import { isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc' |
8 | import { isLiveLatencyModeValid } from '../video-lives' | 8 | import { isLiveLatencyModeValid } from '../video-lives' |
9 | import { | 9 | import { |
10 | isVideoDescriptionValid, | ||
10 | isVideoDurationValid, | 11 | isVideoDurationValid, |
11 | isVideoNameValid, | 12 | isVideoNameValid, |
12 | isVideoStateValid, | 13 | isVideoStateValid, |
13 | isVideoTagValid, | 14 | isVideoTagValid, |
14 | isVideoTruncatedDescriptionValid, | ||
15 | isVideoViewsValid | 15 | isVideoViewsValid |
16 | } from '../videos' | 16 | } from '../videos' |
17 | import { isActivityPubUrlValid, isActivityPubVideoDurationValid, isBaseActivityValid, setValidAttributedTo } from './misc' | 17 | import { isActivityPubUrlValid, isActivityPubVideoDurationValid, isBaseActivityValid, setValidAttributedTo } from './misc' |
@@ -32,7 +32,7 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
32 | logger.debug('Video has invalid urls', { video }) | 32 | logger.debug('Video has invalid urls', { video }) |
33 | return false | 33 | return false |
34 | } | 34 | } |
35 | if (!setRemoteVideoTruncatedContent(video)) { | 35 | if (!setRemoteVideoContent(video)) { |
36 | logger.debug('Video has invalid content', { video }) | 36 | logger.debug('Video has invalid content', { video }) |
37 | return false | 37 | return false |
38 | } | 38 | } |
@@ -168,7 +168,7 @@ function isRemoteStringIdentifierValid (data: any) { | |||
168 | } | 168 | } |
169 | 169 | ||
170 | function isRemoteVideoContentValid (mediaType: string, content: string) { | 170 | function isRemoteVideoContentValid (mediaType: string, content: string) { |
171 | return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) | 171 | return mediaType === 'text/markdown' && isVideoDescriptionValid(content) |
172 | } | 172 | } |
173 | 173 | ||
174 | function setValidRemoteIcon (video: any) { | 174 | function setValidRemoteIcon (video: any) { |
@@ -194,9 +194,9 @@ function setValidRemoteVideoUrls (video: any) { | |||
194 | return true | 194 | return true |
195 | } | 195 | } |
196 | 196 | ||
197 | function setRemoteVideoTruncatedContent (video: any) { | 197 | function setRemoteVideoContent (video: any) { |
198 | if (video.content) { | 198 | if (video.content) { |
199 | video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max }) | 199 | video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max }) |
200 | } | 200 | } |
201 | 201 | ||
202 | return true | 202 | return true |
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 17750379d..3dc5504e3 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -86,7 +86,7 @@ function isFileValid (options: { | |||
86 | 86 | ||
87 | // The file exists | 87 | // The file exists |
88 | const file = fileArray[0] | 88 | const file = fileArray[0] |
89 | if (!file || !file.originalname) return false | 89 | if (!file?.originalname) return false |
90 | 90 | ||
91 | // Check size | 91 | // Check size |
92 | if ((maxSize !== null) && file.size > maxSize) return false | 92 | if ((maxSize !== null) && file.size > maxSize) return false |
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts index 60b29dc89..a20de0c4a 100644 --- a/server/helpers/custom-validators/plugins.ts +++ b/server/helpers/custom-validators/plugins.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { exists, isArray, isSafePath } from './misc' | ||
2 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model' | ||
3 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 3 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model' | ||
6 | import { isUrlValid } from './activitypub/misc' | 5 | import { isUrlValid } from './activitypub/misc' |
6 | import { exists, isArray, isSafePath } from './misc' | ||
7 | 7 | ||
8 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS | 8 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS |
9 | 9 | ||
@@ -29,7 +29,7 @@ function isPluginDescriptionValid (value: string) { | |||
29 | return exists(value) && validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.DESCRIPTION) | 29 | return exists(value) && validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.DESCRIPTION) |
30 | } | 30 | } |
31 | 31 | ||
32 | function isPluginVersionValid (value: string) { | 32 | function isPluginStableVersionValid (value: string) { |
33 | if (!exists(value)) return false | 33 | if (!exists(value)) return false |
34 | 34 | ||
35 | const parts = (value + '').split('.') | 35 | const parts = (value + '').split('.') |
@@ -37,6 +37,19 @@ function isPluginVersionValid (value: string) { | |||
37 | return parts.length === 3 && parts.every(p => validator.isInt(p)) | 37 | return parts.length === 3 && parts.every(p => validator.isInt(p)) |
38 | } | 38 | } |
39 | 39 | ||
40 | function isPluginStableOrUnstableVersionValid (value: string) { | ||
41 | if (!exists(value)) return false | ||
42 | |||
43 | // suffix is beta.x or alpha.x | ||
44 | const [ stable, suffix ] = value.split('-') | ||
45 | if (!isPluginStableVersionValid(stable)) return false | ||
46 | |||
47 | const suffixRegex = /^(rc|alpha|beta)\.\d+$/ | ||
48 | if (suffix && !suffixRegex.test(suffix)) return false | ||
49 | |||
50 | return true | ||
51 | } | ||
52 | |||
40 | function isPluginEngineValid (engine: any) { | 53 | function isPluginEngineValid (engine: any) { |
41 | return exists(engine) && exists(engine.peertube) | 54 | return exists(engine) && exists(engine.peertube) |
42 | } | 55 | } |
@@ -156,7 +169,8 @@ export { | |||
156 | isPackageJSONValid, | 169 | isPackageJSONValid, |
157 | isThemeNameValid, | 170 | isThemeNameValid, |
158 | isPluginHomepage, | 171 | isPluginHomepage, |
159 | isPluginVersionValid, | 172 | isPluginStableVersionValid, |
173 | isPluginStableOrUnstableVersionValid, | ||
160 | isPluginNameValid, | 174 | isPluginNameValid, |
161 | isPluginDescriptionValid, | 175 | isPluginDescriptionValid, |
162 | isLibraryCodeValid, | 176 | isLibraryCodeValid, |
diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.ts index b9f45c282..94fda05aa 100644 --- a/server/helpers/custom-validators/servers.ts +++ b/server/helpers/custom-validators/servers.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { CONFIG } from '@server/initializers/config' | ||
2 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
3 | import { isTestOrDevInstance } from '../core-utils' | ||
4 | import { exists, isArray } from './misc' | 4 | import { exists, isArray } from './misc' |
5 | 5 | ||
6 | function isHostValid (host: string) { | 6 | function isHostValid (host: string) { |
@@ -10,7 +10,7 @@ function isHostValid (host: string) { | |||
10 | } | 10 | } |
11 | 11 | ||
12 | // We validate 'localhost', so we don't have the top level domain | 12 | // We validate 'localhost', so we don't have the top level domain |
13 | if (isTestOrDevInstance()) { | 13 | if (CONFIG.WEBSERVER.HOSTNAME === 'localhost') { |
14 | isURLOptions.require_tld = false | 14 | isURLOptions.require_tld = false |
15 | } | 15 | } |
16 | 16 | ||
diff --git a/server/helpers/custom-validators/video-studio.ts b/server/helpers/custom-validators/video-studio.ts index 19e7906d5..68dfec8dd 100644 --- a/server/helpers/custom-validators/video-studio.ts +++ b/server/helpers/custom-validators/video-studio.ts | |||
@@ -4,6 +4,7 @@ import { buildTaskFileFieldname } from '@server/lib/video-studio' | |||
4 | import { VideoStudioTask } from '@shared/models' | 4 | import { VideoStudioTask } from '@shared/models' |
5 | import { isArray } from './misc' | 5 | import { isArray } from './misc' |
6 | import { isVideoFileMimeTypeValid, isVideoImageValid } from './videos' | 6 | import { isVideoFileMimeTypeValid, isVideoImageValid } from './videos' |
7 | import { forceNumber } from '@shared/core-utils' | ||
7 | 8 | ||
8 | function isValidStudioTasksArray (tasks: any) { | 9 | function isValidStudioTasksArray (tasks: any) { |
9 | if (!isArray(tasks)) return false | 10 | if (!isArray(tasks)) return false |
@@ -24,7 +25,7 @@ function isStudioCutTaskValid (task: VideoStudioTask) { | |||
24 | 25 | ||
25 | if (!start || !end) return true | 26 | if (!start || !end) return true |
26 | 27 | ||
27 | return parseInt(start + '') < parseInt(end + '') | 28 | return forceNumber(start) < forceNumber(end) |
28 | } | 29 | } |
29 | 30 | ||
30 | function isStudioTaskAddIntroOutroValid (task: VideoStudioTask, indice: number, files: Express.Multer.File[]) { | 31 | function isStudioTaskAddIntroOutroValid (task: VideoStudioTask, indice: number, files: Express.Multer.File[]) { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 3ebfe2937..9e8177f77 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -45,10 +45,6 @@ function isVideoDurationValid (value: string) { | |||
45 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | 45 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) |
46 | } | 46 | } |
47 | 47 | ||
48 | function isVideoTruncatedDescriptionValid (value: string) { | ||
49 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION) | ||
50 | } | ||
51 | |||
52 | function isVideoDescriptionValid (value: string) { | 48 | function isVideoDescriptionValid (value: string) { |
53 | return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)) | 49 | return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)) |
54 | } | 50 | } |
@@ -151,7 +147,6 @@ export { | |||
151 | isVideoCategoryValid, | 147 | isVideoCategoryValid, |
152 | isVideoLicenceValid, | 148 | isVideoLicenceValid, |
153 | isVideoLanguageValid, | 149 | isVideoLanguageValid, |
154 | isVideoTruncatedDescriptionValid, | ||
155 | isVideoDescriptionValid, | 150 | isVideoDescriptionValid, |
156 | isVideoFileInfoHashValid, | 151 | isVideoFileInfoHashValid, |
157 | isVideoNameValid, | 152 | isVideoNameValid, |