X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fplugins.ts;h=a20de0c4a66a2ff094736d245857c1b4ed167713;hb=HEAD;hp=60b29dc894b87aa0fba870f2d6d746915204054d;hpb=3318147300b4f998adf728eb0a5a14a4c1829c51;p=github%2FChocobozzz%2FPeerTube.git 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 @@ -import { exists, isArray, isSafePath } from './misc' import validator from 'validator' +import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model' import { PluginType } from '../../../shared/models/plugins/plugin.type' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model' import { isUrlValid } from './activitypub/misc' +import { exists, isArray, isSafePath } from './misc' const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS @@ -29,7 +29,7 @@ function isPluginDescriptionValid (value: string) { return exists(value) && validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.DESCRIPTION) } -function isPluginVersionValid (value: string) { +function isPluginStableVersionValid (value: string) { if (!exists(value)) return false const parts = (value + '').split('.') @@ -37,6 +37,19 @@ function isPluginVersionValid (value: string) { return parts.length === 3 && parts.every(p => validator.isInt(p)) } +function isPluginStableOrUnstableVersionValid (value: string) { + if (!exists(value)) return false + + // suffix is beta.x or alpha.x + const [ stable, suffix ] = value.split('-') + if (!isPluginStableVersionValid(stable)) return false + + const suffixRegex = /^(rc|alpha|beta)\.\d+$/ + if (suffix && !suffixRegex.test(suffix)) return false + + return true +} + function isPluginEngineValid (engine: any) { return exists(engine) && exists(engine.peertube) } @@ -156,7 +169,8 @@ export { isPackageJSONValid, isThemeNameValid, isPluginHomepage, - isPluginVersionValid, + isPluginStableVersionValid, + isPluginStableOrUnstableVersionValid, isPluginNameValid, isPluginDescriptionValid, isLibraryCodeValid,