diff --git a/peertube-plugin-hello-world/client/common-client-plugin.js b/peertube-plugin-hello-world/client/common-client-plugin.js index a9aa82a..4f6e4d4 100644 --- a/peertube-plugin-hello-world/client/common-client-plugin.js +++ b/peertube-plugin-hello-world/client/common-client-plugin.js @@ -7,69 +7,50 @@ function register ({ registerHook, peertubeHelpers }) { // Videos list registerHook({ - target: 'filter:api.videos.list.trending.params', + target: 'filter:api.trending-videos.videos.list.params', handler: params => Object.assign({}, params, { sort: '-views' }) }) registerHook({ - target: 'filter:api.videos.list.trending.result', + target: 'filter:api.trending-videos.videos.list.result', handler: result => addSymbolToVideoNameResult(result, '<3') }) registerHook({ - target: 'filter:api.videos.list.local.params', + target: 'filter:api.local-videos.videos.list.params', handler: params => Object.assign({}, params, { sort: '-views' }) }) registerHook({ - target: 'filter:api.videos.list.local.result', + target: 'filter:api.local-videos.videos.list.result', handler: result => addSymbolToVideoNameResult(result, ':)') }) registerHook({ - target: 'filter:api.videos.list.recently-added.params', + target: 'filter:api.recently-added-videos.videos.list.params', handler: params => Object.assign({}, params, { filter: 'all-local' }) }) registerHook({ - target: 'filter:api.videos.list.recently-added.result', + target: 'filter:api.recently-added-videos.videos.list.result', handler: result => addSymbolToVideoNameResult(result, 'o/') }) registerHook({ - target: 'filter:api.videos.list.user-subscriptions.params', + target: 'filter:api.user-subscriptions-videos.videos.list.params', handler: params => Object.assign({}, params, { sort: '-views' }) }) registerHook({ - target: 'filter:api.videos.list.user-subscriptions.result', + target: 'filter:api.user-subscriptions-videos.videos.list.result', handler: result => addSymbolToVideoNameResult(result, ':D') }) - // Search list + // Fake hook registerHook({ - target: 'filter:api.search.videos.list.result', - handler: result => { - result.data.forEach(v => v.name += ' SEARCH') - - return { - total: result.total, - data: result.data - } - } - }) - - registerHook({ - target: 'filter:api.search.video-channels.list.result', - handler: result => { - result.data.forEach(v => v.displayName += ' :p') - - return { - total: result.total, - data: result.data - } - } + target: 'fakeHook', + handler: () => console.log('fake hook') }) } diff --git a/peertube-plugin-hello-world/client/search-client-plugin.js b/peertube-plugin-hello-world/client/search-client-plugin.js new file mode 100644 index 0000000..641051d --- /dev/null +++ b/peertube-plugin-hello-world/client/search-client-plugin.js @@ -0,0 +1,56 @@ +function register ({ registerHook, peertubeHelpers }) { + + registerHook({ + target: 'action:search.init', + handler: () => console.log('Search init') + }) + + registerHook({ + target: 'filter:api.search.videos.list.result', + handler: result => { + result.data.forEach(v => v.name += ' SEARCH') + + return { + total: result.total, + data: result.data + } + } + }) + + registerHook({ + target: 'filter:api.search.video-channels.list.result', + handler: result => { + result.data.forEach(v => v.displayName += ' :p') + + return { + total: result.total, + data: result.data + } + } + }) + +} + +export { + register +} + +function onApplicationInit (peertubeHelpers) { + console.log('Hello application world') + + const baseStaticUrl = peertubeHelpers.getBaseStaticRoute() + const imageUrl = baseStaticUrl + '/images/chocobo.png' + + const topLeftBlock = document.querySelector('.top-left-block') + + topLeftBlock.style.backgroundImage = 'url(' + imageUrl + ')' +} + +function addSymbolToVideoNameResult (result, symbol) { + result.data.forEach(v => v.name += ' ' + symbol) + + return { + data: result.data, + total: result.total + } +} diff --git a/peertube-plugin-hello-world/client/video-watch-client-plugin.js b/peertube-plugin-hello-world/client/video-watch-client-plugin.js index 739150c..9d77625 100644 --- a/peertube-plugin-hello-world/client/video-watch-client-plugin.js +++ b/peertube-plugin-hello-world/client/video-watch-client-plugin.js @@ -21,7 +21,7 @@ function register ({ registerHook, peertubeHelpers }) { registerHook({ target: 'filter:api.video-watch.video-threads.list.result', handler: result => { - result.comments.forEach(c => c.text += ' THREAD') + result.data.forEach(c => c.text += ' THREAD') return result } diff --git a/peertube-plugin-hello-world/main.js b/peertube-plugin-hello-world/main.js index c47f81f..a6263a2 100644 --- a/peertube-plugin-hello-world/main.js +++ b/peertube-plugin-hello-world/main.js @@ -6,6 +6,11 @@ async function register ({ registerHook, registerSetting, settingsManager, stora handler: () => displayHelloWorld(settingsManager, defaultAdmin) }) + registerHook({ + target: 'unknown-hook', + handler: () => console.log('fake hook') + }) + registerSetting({ name: 'admin-name', label: 'Admin name', diff --git a/peertube-plugin-hello-world/package.json b/peertube-plugin-hello-world/package.json index 6b6f315..4a422ff 100644 --- a/peertube-plugin-hello-world/package.json +++ b/peertube-plugin-hello-world/package.json @@ -1,6 +1,6 @@ { "name": "peertube-plugin-hello-world", - "version": "0.0.10", + "version": "0.0.11", "description": "Hello world PeerTube plugin example", "engine": { "peertube": ">=1.3.0" @@ -28,6 +28,10 @@ { "script": "client/video-watch-client-plugin.js", "scopes": [ "video-watch" ] + }, + { + "script": "client/search-client-plugin.js", + "scopes": [ "search" ] } ] }