aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/plugins.ts22
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 @@
1import { exists, isArray, isSafePath } from './misc'
2import validator from 'validator' 1import validator from 'validator'
2import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model'
3import { PluginType } from '../../../shared/models/plugins/plugin.type' 3import { PluginType } from '../../../shared/models/plugins/plugin.type'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model'
6import { isUrlValid } from './activitypub/misc' 5import { isUrlValid } from './activitypub/misc'
6import { exists, isArray, isSafePath } from './misc'
7 7
8const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS 8const 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
32function isPluginVersionValid (value: string) { 32function 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
40function 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
40function isPluginEngineValid (engine: any) { 53function 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,