X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fplugins.ts;h=a20de0c4a66a2ff094736d245857c1b4ed167713;hb=c56dd2807fe5d129907b9bf8c42656a8314d754b;hp=5a4531f72ebdea684bdddcb105276d2c0497639f;hpb=c2777c1dfe688c8fab1ef2fed50e360100fa9198;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts index 5a4531f72..a20de0c4a 100644 --- a/server/helpers/custom-validators/plugins.ts +++ b/server/helpers/custom-validators/plugins.ts @@ -1,20 +1,21 @@ -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 function isPluginTypeValid (value: any) { - return exists(value) && validator.isInt('' + value) && PluginType[value] !== undefined + return exists(value) && + (value === PluginType.PLUGIN || value === PluginType.THEME) } function isPluginNameValid (value: string) { return exists(value) && validator.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) && - validator.matches(value, /^[a-z-]+$/) + validator.matches(value, /^[a-z-0-9]+$/) } function isNpmPluginNameValid (value: string) { @@ -28,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('.') @@ -36,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) } @@ -83,7 +97,7 @@ function isThemeNameValid (name: string) { return isPluginNameValid(name) } -function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { +function isPackageJSONValid (packageJSON: PluginPackageJSON, pluginType: PluginType) { let result = true const badFields: string[] = [] @@ -155,7 +169,8 @@ export { isPackageJSONValid, isThemeNameValid, isPluginHomepage, - isPluginVersionValid, + isPluginStableVersionValid, + isPluginStableOrUnstableVersionValid, isPluginNameValid, isPluginDescriptionValid, isLibraryCodeValid,