Add other hooks to hello world plugin

This commit is contained in:
Chocobozzz 2020-08-21 14:45:18 +02:00
parent 76bd650ad0
commit 47a4d19252
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 67 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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({ registerSetting({
name: 'admin-name', name: 'admin-name',
label: 'Admin name', label: 'Admin name',

View File

@ -36,6 +36,14 @@
{ {
"script": "client/login-client-plugin.js", "script": "client/login-client-plugin.js",
"scopes": [ "login" ] "scopes": [ "login" ]
},
{
"script": "client/embed-client-plugin.js",
"scopes": [ "embed" ]
},
{
"script": "client/video-edit-client-plugin.js",
"scopes": [ "video-edit" ]
} }
], ],
"translations": { "translations": {