]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/plugins.ts
Add welcome modal
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / plugins.ts
index e0a6f98a7a5717eb599f2f174291acebbbbbfed7..63af91a44a7ec5dcef814fb7ef1da4d68c842234 100644 (file)
@@ -41,10 +41,14 @@ function isPluginEngineValid (engine: any) {
 }
 
 function isPluginHomepage (value: string) {
-  return isUrlValid(value)
+  return exists(value) && (!value || isUrlValid(value))
 }
 
-function isStaticDirectoriesValid (staticDirs: any) {
+function isPluginBugs (value: string) {
+  return exists(value) && (!value || isUrlValid(value))
+}
+
+function areStaticDirectoriesValid (staticDirs: any) {
   if (!exists(staticDirs) || typeof staticDirs !== 'object') return false
 
   for (const key of Object.keys(staticDirs)) {
@@ -54,14 +58,24 @@ function isStaticDirectoriesValid (staticDirs: any) {
   return true
 }
 
-function isClientScriptsValid (clientScripts: any[]) {
+function areClientScriptsValid (clientScripts: any[]) {
   return isArray(clientScripts) &&
     clientScripts.every(c => {
       return isSafePath(c.script) && isArray(c.scopes)
     })
 }
 
-function isCSSPathsValid (css: any[]) {
+function areTranslationPathsValid (translations: any) {
+  if (!exists(translations) || typeof translations !== 'object') return false
+
+  for (const key of Object.keys(translations)) {
+    if (!isSafePath(translations[key])) return false
+  }
+
+  return true
+}
+
+function areCSSPathsValid (css: any[]) {
   return isArray(css) && css.every(c => isSafePath(c))
 }
 
@@ -75,11 +89,12 @@ function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginT
     isPluginEngineValid(packageJSON.engine) &&
     isPluginHomepage(packageJSON.homepage) &&
     exists(packageJSON.author) &&
-    isUrlValid(packageJSON.bugs) &&
+    isPluginBugs(packageJSON.bugs) &&
     (pluginType === PluginType.THEME || isSafePath(packageJSON.library)) &&
-    isStaticDirectoriesValid(packageJSON.staticDirs) &&
-    isCSSPathsValid(packageJSON.css) &&
-    isClientScriptsValid(packageJSON.clientScripts)
+    areStaticDirectoriesValid(packageJSON.staticDirs) &&
+    areCSSPathsValid(packageJSON.css) &&
+    areClientScriptsValid(packageJSON.clientScripts) &&
+    areTranslationPathsValid(packageJSON.translations)
 }
 
 function isLibraryCodeValid (library: any) {