From 2158ac90341dc3fcae958540de65032da25c8d6e Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 14 May 2020 11:10:26 +0200 Subject: Add server plugin filter hooks for import with torrent and url (#2621) * Add server plugin filter hooks for import with torrent and url * WIP: pre and post-import filter hooks * Rebased * Cleanup filters to accept imports Co-authored-by: Chocobozzz --- server/tests/fixtures/peertube-plugin-test/main.js | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'server/tests/fixtures/peertube-plugin-test/main.js') diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index 69796ab07..a45e98fb5 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -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 } } -- cgit v1.2.3