From 47a4d19252108a77984030451bbf1a6a11af80be Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Aug 2020 14:45:18 +0200 Subject: [PATCH] Add other hooks to hello world plugin --- .../client/embed-client-plugin.js | 12 +++++++++ .../client/video-edit-client-plugin.js | 20 ++++++++++++++ peertube-plugin-hello-world/main.js | 27 +++++++++++++++++++ peertube-plugin-hello-world/package.json | 8 ++++++ 4 files changed, 67 insertions(+) create mode 100644 peertube-plugin-hello-world/client/embed-client-plugin.js create mode 100644 peertube-plugin-hello-world/client/video-edit-client-plugin.js diff --git a/peertube-plugin-hello-world/client/embed-client-plugin.js b/peertube-plugin-hello-world/client/embed-client-plugin.js new file mode 100644 index 0000000..b69a4d9 --- /dev/null +++ b/peertube-plugin-hello-world/client/embed-client-plugin.js @@ -0,0 +1,12 @@ +function register ({ registerHook, peertubeHelpers }) { + registerHook({ + target: 'action:embed.player.loaded', + handler: () => alert('video loaded') + }) + + console.log(peertubeHelpers.translate('toto')) +} + +export { + register +} diff --git a/peertube-plugin-hello-world/client/video-edit-client-plugin.js b/peertube-plugin-hello-world/client/video-edit-client-plugin.js new file mode 100644 index 0000000..9d81283 --- /dev/null +++ b/peertube-plugin-hello-world/client/video-edit-client-plugin.js @@ -0,0 +1,20 @@ +function register ({ registerVideoField }) { + console.log('loading video edit stuff') + + { + const commonOptions = { + name: 'hello-world-field', + label: 'Super field', + type: 'input', + default: 'hello' + } + + for (const type of [ 'upload', 'import-url', 'update' ]) { + registerVideoField(commonOptions, { type }) + } + } +} + +export { + register +} diff --git a/peertube-plugin-hello-world/main.js b/peertube-plugin-hello-world/main.js index e88c175..36c0082 100644 --- a/peertube-plugin-hello-world/main.js +++ b/peertube-plugin-hello-world/main.js @@ -45,6 +45,33 @@ async function register ({ } }) + { + const fieldName = 'hello-world-field' + + registerHook({ + target: 'action:api.video.updated', + handler: ({ video, body }) => { + if (!body.pluginData) return + + storageManager.storeData(fieldName + '-' + video.id, body.pluginData[fieldName]) + } + }) + + registerHook({ + target: 'filter:api.video.get.result', + handler: async (video) => { + if (!video) return video + + if (!video.pluginData) video.pluginData = {} + + const result = await storageManager.getData(fieldName + '-' + video.id) + video.pluginData[fieldName] = result + + return video + } + }) + } + registerSetting({ name: 'admin-name', label: 'Admin name', diff --git a/peertube-plugin-hello-world/package.json b/peertube-plugin-hello-world/package.json index 54fa8be..ab11dfd 100644 --- a/peertube-plugin-hello-world/package.json +++ b/peertube-plugin-hello-world/package.json @@ -36,6 +36,14 @@ { "script": "client/login-client-plugin.js", "scopes": [ "login" ] + }, + { + "script": "client/embed-client-plugin.js", + "scopes": [ "embed" ] + }, + { + "script": "client/video-edit-client-plugin.js", + "scopes": [ "video-edit" ] } ], "translations": {