]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/fixtures/peertube-plugin-test/main.js
Add server plugin filter hooks for import with torrent and url (#2621)
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test / main.js
index 69796ab07fd10af113ddf3684e6c5af2f2d14229..a45e98fb56945d3247a6f38dc0d61dce31daa5c5 100644 (file)
@@ -50,7 +50,47 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
     target: 'filter:api.video.upload.accept.result',
     handler: ({ accepted }, { videoBody }) => {
       if (!accepted) return { accepted: false }
-      if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
+      if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
+
+      return { accepted: true }
+    }
+  })
+
+  registerHook({
+    target: 'filter:api.video.pre-import-url.accept.result',
+    handler: ({ accepted }, { videoImportBody }) => {
+      if (!accepted) return { accepted: false }
+      if (videoImportBody.targetUrl.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
+
+      return { accepted: true }
+    }
+  })
+
+  registerHook({
+    target: 'filter:api.video.pre-import-torrent.accept.result',
+    handler: ({ accepted }, { videoImportBody }) => {
+      if (!accepted) return { accepted: false }
+      if (videoImportBody.name.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
+
+      return { accepted: true }
+    }
+  })
+
+  registerHook({
+    target: 'filter:api.video.post-import-url.accept.result',
+    handler: ({ accepted }, { video }) => {
+      if (!accepted) return { accepted: false }
+      if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
+
+      return { accepted: true }
+    }
+  })
+
+  registerHook({
+    target: 'filter:api.video.post-import-torrent.accept.result',
+    handler: ({ accepted }, { video }) => {
+      if (!accepted) return { accepted: false }
+      if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
 
       return { accepted: true }
     }