diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/plugins.ts | 22 |
1 files changed, 18 insertions, 4 deletions
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, |