]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/plugins.ts
Fix stats time metric
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / plugins.ts
index 3af72547b349630eaa7ecc72aba836344dcc61bc..60b29dc894b87aa0fba870f2d6d746915204054d 100644 (file)
@@ -2,19 +2,20 @@ import { exists, isArray, isSafePath } from './misc'
 import validator from 'validator'
 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 { PluginPackageJSON } from '../../../shared/models/plugins/plugin-package-json.model'
 import { isUrlValid } from './activitypub/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) {
@@ -83,7 +84,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[] = []
 
@@ -146,8 +147,8 @@ function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginT
 }
 
 function isLibraryCodeValid (library: any) {
-  return typeof library.register === 'function'
-    && typeof library.unregister === 'function'
+  return typeof library.register === 'function' &&
+    typeof library.unregister === 'function'
 }
 
 export {